I have a .doc file in my folder. I want to save the same .doc file many times with different names.
Example:
I have a .doc file named myfile.doc.
I want it to be saved as myfile1.doc, myfile2.doc, myfile3.doc.
This needs to be done for up to 30 files like that.
How can I do this in Python?
I Tried this Script. But There is an Error:-
import shutil
dateoffile = input('Please Enter 4 Digit Date')
filenumber = input('Please Enter File Number')
hyphen1 = '-'
doctrname = 'KW'
hyphen2 = '-'
year = '2011'
original = 'dateoffile+hyphen1+doctrname+hyphen2+year.doc'
for i in range(1,31): # creates 30 files named from 1 to 30
new = filenumber+i+'.doc' # the +i+ is used to have 30 different names and not crash
shutil.copyfile(original, new) # You can even do original='pathtofile/orienter code hereginaldocfile.doc' and new='pathtonewfile/newdocfile'+i+'.doc'
Ther Error is :-
new = filenumber+i+'.doc' # the +i+ is used to have 30 different names and not crash TypeError: can only concatenate str (not "int") to str
Can You Explain Why it is Coming Like This ???
you can try something like this :
This should work