I need to copy various files for several times with a specific name and I wanted to make the process automate. This is my python code:
number_of_copies = int(raw_input("enter number of copies "))
copy_number = 1
infile = raw_input("file to be copied ")
new_file = raw_input("What's the name of the new file?")
extension = ".fastq"
indata = open(infile)
file_to_copy = str(indata.read())
while copy_number < number_of_copies:
copy = open(new_file + "-" + str(copy_number) + extension, 'w')
copy_number = copy_number + 1
As noted in the comments, using
shutil is more efficient.
You're getting errors because your OS does newline translation on text files. So to use the above code correctly on all files you need to open them in binary mode, eg
open(new_file + "-" + str(copy_number) + extension, 'wb')