Python Forum

Full Version: Copy mp3 file multiple times and rename
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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]
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)
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]
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)
   
I got working OK, Thank You for the help.