python文件自动归类

2018年11月3日22:21:08 发表评论 1,214 views
最近做了一个文件自动归类的脚本,测试效果不错,源码:

path = 'D://Users/Administrator/Desktop/Walden'
path2 = path + '/'
files = os.listdir(path)

for f in files:
    folder_name = path + f.split('.')[-1]
    folder_name2 = path2 + f.split('.')[-1]
    if not os.path.exists(folder_name2):
        os.makedirs(folder_name2)
        shutil.move(path2+f,folder_name2)
    else:
        shutil.move(path2 + f,folder_name2)

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: