import os, re, string path = "/Users/wanggeng/work/html/mygame/view/" def ppp (path, file ): if os.path.isfile (path + file ): portion = os.path.splitext (file ) newname = portion[0] + ".html" print (file, newname ) os.rename (path + file, path + newname ) print portion else: newpath = path + file + "/" files = os.listdir (newpath ) for f in files: ppp (newpath, f ) ppp (path, "")
1 ChiChou 2015-09-10 12:50:50 +08:00 用 shell 不是更方便? 0 0 |
![]() | 2 superwg1984 OP @ChiChou 别提了,我现学 shell,俩小时没弄出来...越来越不喜欢 shell 了 |
![]() | 3 fuge 2015-09-10 13:44:10 +08:00 find | xargs |
![]() | 5 omph 2015-09-10 19:50:19 +08:00 shell 比较灵活,楼主没找对方向 find "$path" -type f -execdir rename 's/.[\w]+$/.html/' '{}' + |
6 kaisfm 2015-09-16 12:01:14 +08:00 有一个东东叫 walker |