文件夹对比,,买了个移动硬盘备份 但是


买了个移动硬盘备份 但是时常这加点 那加点 想要同步不太容易啊

只进行了对比操作 很简单 本来应该加个自动复制的 后来想想 还是手工比较信赖 哈哈

import sysimport osdef scanfolder(path):    root = path    s = set()    scan(s, path, "")    return sdef scan(s,root,path):    folder = os.path.join(root, path)    files = os.listdir(folder)    for file in files:        filepath = os.path.join(folder, file)        if os.path.isdir(filepath):            s.add(path+file+"\\\\")            scan(s, root, path+file+"\\\\")        elif os.path.isfile(filepath):            s.add(path+file)def compare(a, b):    print("Scaning folder a...")    seta = scanfolder(a)    print("Scaning folder b...")    setb = scanfolder(b)    print("Comparing...")    diff = seta.difference(setb)    return diffdef report(diff):    folders = []    files = []    for file in diff:        if file.endswith("\\\\"):            folders.append(file)        else:            files.append(file)    print("lose folders:")    for folder in folders:        print("\\t"+folder)    print("lose files:")    for file in files:        print("\\t"+file)def main():    s = compare("E:\\\\单曲\\\\国语音乐", "H:\\\\音乐文件\\\\国语音乐")    report(s)if __name__ == '__main__':    main()#该片段来自于http://byrx.net

评论关闭