import os """判断两个文件夹有无相同文件:根据文件名判断""" def fileList(path): filelist = {} n = 1 for root,folders,files in os.walk(path): for file in files: print(‘\rHas scanned %s files ------- %s‘ % (n,path) ,end=‘‘) n += 1 filelist[file] = os.path.join(root,file) print(‘\n‘) return filelist def compare(path1, path2): dict1 = fileList(path1) dict2 = fileList(path2) for key in dict1: if key not in dict2: print(dict1[key]) if __name__ == ‘__main__‘: path1 = r‘G:\document\英语‘ path2 = r‘G:\document\书籍‘ compare(path1,path2) print("Done.")
原文:https://www.cnblogs.com/wztshine/p/12365239.html