【发布时间】:2021-08-17 19:01:23
【问题描述】:
我有一个带有三个参数的函数
- list_to_copy : 我要复制的文件列表。
- list_to_avoid : 我不想复制的列表,可能存在于 list_to_copy 中
- 目标是文件所在的路径。
def copy_files(self, list_to_copy, list_to_avoid, destination):
# Copy a file from list to destination making sure file is not
# duplicated regarding the name.
for copied_file in list_to_copy:
for avoid_file in list_to_avoid:
if not filecmp.cmp(copied_file, avoid_file):
shutil.copy(copied_file, destination)
我的主要问题是我不知道如何使用filecmp.cmp(file1, file2) 将copied_file 与list_to_avoid 中的所有文件进行比较
按文件名(字符串)检查笔记对我来说效率不高。
【问题讨论】:
-
是你所拥有的只是效率低下的问题吗?
-
@ChaseLp 我没那么先进。我在复制文件后重命名文件,因此我需要与不同的方式进行比较以避免重复文件。如果你有建议帮助我^_^
标签: python python-3.x