python - 检查 shutil.copyfile 何时完成

标签 python file-copying shutil

我有这样一段代码:

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

这里的问题是,在 #do further actions 处,我使用复制的文件,因此我需要确保 shutil.copyfile 函数完成它们的任务。我怎样才能确定这一点?

最佳答案

shutil 函数应仅在操作完成后返回。如果操作系统级别没有发生任何有趣的事情,那么这样做应该是安全的。

如果您知道文件的大小,您可以检查它是否正确。

关于python - 检查 shutil.copyfile 何时完成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3141296/

相关文章:

python - 撞车时如何清理?

python - @staticmethod 和@classmethod 的区别

Python Regex - 在日期之前或之后高效

python - 处理表单之间的数据

batch-file - 使用 .bat 将文件复制到另一个位置

r - 在文件夹之间移动文件

python - Shutil.move 是否保证删除或抛出?

c++ - 复制文本文件的更好方法是什么?

python - 如何改进在 Python 中移动所有不包含特定日期的文件?

python - 使用特殊情况处理在 Python 中实现递归复制