I'm using shutil library. When I using :
backuped = shutil.copyfile(file1, file2)
file2
is empty. There is not any problem with shutil.move
. How can I copy file without losing data?
I'm using shutil library. When I using :
backuped = shutil.copyfile(file1, file2)
file2
is empty. There is not any problem with shutil.move
. How can I copy file without losing data?
Are you on Mac? Shutil does not work properly on Mac according to the PyScripter pop-up.
You also need to be more specific, I could not replicate this problem. However, I would suggest checking:
You COULD do it manually with files as I'll show below, however I think this way is slower than other built-in methods.
with open (file1, "rb") as f1:
with open (file2, "wb") as f2:
f2.writelines(f1.readlines())
This created an exact copy of the file with the location file1
to the location file2
. This method works with all files and can be implemented with pickle to encrypt and serialise objects.
file2
does not need to already be a file either.