I have a function with three args
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)
My main problem is I don't know how to compare copied_file
with all files in list_to_avoid
using filecmp.cmp(file1, file2)
Note checking by name of the file (string) isn't efficient for me.
from filecmp import cmp
from shutil import copy
from os import scandir
def copy_files(list_to_copy,destination):
# Copy a file from list to destination making sure file is not duplicated regarding the content.
for copied_file in list_to_copy:
for avoid_file in scandir(destination):
if cmp(copied_file,avoid_file):
break
else:
copy(copied_file, destination)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.