Python Forum
Copy mp3 file multiple times and rename
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Copy mp3 file multiple times and rename
#1
Hi, I need to copy a mp3 file and make 6 additional copies for a total of 7 mp3 files, Each mp3 file needs to have the file number beginning from number 2-account, 4-account, 6-account, 8-account, 10-account, 12-account, 14-account.
This is what I have tried so far but it's not working.
I hope you can help me out thank you


[python]

import subprocess

src="C:/Users/new kichen/Desktop/cpier1/01-account.mp3"
dst="C:/Users/new kichen/Desktop/cpier2/02-account.mp3"
cmd='copy "%s" "%s"' % (src, dst)







[\python]
Reply
#2
Are you sure you have the filepaths correct (I'm looking at the "new kichen" component)?

For copying a file, I would prefer to stay in python and not run a subprocess. It should be simpler and you will get better error messages. If you don't need owner/timestamp information kept up to date and you don't need the destination to be a directory, then I'd use shutil.copyfile

import shutil
src = r"C:/Users/new kichen/Desktop/cpier1/01-account.mp3"
dst = r"C:/Users/new kichen/Desktop/cpier2/02-account.mp3"
shutil.copyfile(src, dst)
Reply
#3
Hi, bowlofred the code works right to make one copy, So what will be the best way to make all the copies that I need, also when the script is run there is no indication of whats going on.. only a blinking cursor.

I copy the code and duplicated and in the second copy of the code I increased the file number from 2 to 4 and it works just fine, But that is a lot of repetitive code lines, It works that's what it is important to me right now, If anybody has any better solution It will be appreciated. Thanks for the help.

This is what I did.

[python

import shutil
src = r"C:/Users/new kichen/Desktop/cpier1/01-account.mp3"
dst = r"C:/Users/new kichen/Desktop/cpier2/02-account.mp3"
shutil.copyfile(src, dst)

import shutil
src = r"C:/Users/new kichen/Desktop/cpier1/01-account.mp3"
dst = r"C:/Users/new kichen/Desktop/cpier2/04-account.mp3"
shutil.copyfile(src, dst)

[/python]
Reply
#4
What feedback does the command-line "copy" give you? I don't think it does anything either.

Just run it in a loop. Print something between files so you have something to watch if it takes a while.

import shutil
src = "my_source_file"
for count in range(1,11):
   dst = f"myfile_but_number_{count:02d}"
   print(f"Starting copy from {src} to {dst}")
   shutil.copyfile(src, dst)
   
Reply
#5
I got working OK, Thank You for the help.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Why is the copy method name in python list copy and not `__copy__`? YouHoGeon 2 273 Apr-04-2024, 01:18 AM
Last Post: YouHoGeon
  Copy Paste excel files based on the first letters of the file name Viento 2 439 Feb-07-2024, 12:24 PM
Last Post: Viento
  Rename first row in a CSV file James_S 3 584 Dec-17-2023, 05:20 AM
Last Post: James_S
  rename file RolanRoll 0 532 May-18-2023, 02:17 PM
Last Post: RolanRoll
  '' FTP '' File upload with a specified string and rename midomarc 1 1,160 Apr-17-2023, 03:04 AM
Last Post: bowlofred
  is it possible to copy image from email and place into excel file? cubangt 3 1,271 Nov-30-2022, 05:11 PM
Last Post: snippsat
  Please help me [copy and paste file from src to dst] midomarc 2 1,017 Nov-24-2022, 10:13 PM
Last Post: midomarc
  rename same file names in different directories elnk 0 712 Nov-04-2022, 05:23 PM
Last Post: elnk
  Rename multiple photos with DateTimeOriginal timestamp Stjude1982 2 1,156 Oct-21-2022, 12:24 AM
Last Post: Pedroski55
  Saving the times a script is run to a file or ... 3Pinter 7 1,397 Oct-19-2022, 05:38 PM
Last Post: 3Pinter

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020