桌面文件自动整理脚本

__author__ = 'zhangcx'
import os
import shutil

path = r'C:\Users\zhangcx\Desktop'
lst = sorted(os.listdir(path))
for i in lst:
    a,b = os.path.splitext(i)
    b = b[1:]
    print('{f}:{ext}'.format(f=a,ext=b))
    if b:
        olddir = '%s\%s'% (path, i)
        newdir = '%s\%s' % (path,b.lower())
        if not os.listdir(path).__contains__(b.lower()):
            os.mkdir(newdir)
        shutil.move(olddir,newdir)
        #print(olddir)
        #print(newdir)

 

posted @ 2016-01-08 00:09  玻璃鱼儿  阅读(445)  评论(0编辑  收藏  举报