Python: verifying shutil.copyfile execution

I have a code like this:

for file in file_list: shutil.copyfile(file,newpath) #do further actions 

And so the question is, in #do further actions I use the copied files, so I need to make sure that the shutil.copyfile functions complete their task. How can I be sure of this?

+6
python shutil file-copying
source share
2 answers

Shutil functions should be returned only after the operation is completed. If nothing funny happens at the OS level, it should be safe this way.

If you know the file size, you can check if this is correct.

+5
source share

copyfile is a blocking function. When you get to #do further actions , this should always be done. Do you have a problem if it is not?

+3
source share

All Articles