批量修改文件名的py脚本

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os

def trimfile(dir):
    for fn in os.listdir(dir):
        sfile = os.path.join(dir, fn)
        if os.path.isdir(sfile):
            trimfile(sfile)
            continue
        if '~' in fn:
            newfile = os.path.join(dir, fn[1:])
            open(newfile, 'wb').write(open(sfile,'rb').read())
            print(newfile)

if __name__=="__main__":
    trimfile(os.path.abspath('.'))

  

posted @ 2012-04-27 10:14  张云贵  Views(1247)  Comments(0Edit  收藏  举报