摘要: 有些时候某些文件夹下的文件路径太长,超出了windows系统的限制,导致此文件夹不能被删除。 此时我们需要先subst此文件夹然后再删除,以下脚本帮你自动完成。代码:importosimportsysimportshutilimportsubprocessdefrunCommand(cmd):returnsubprocess.call(cmd)defsubstDriveForPath(drive,path):substcmd="subst"+""+drive+""+pathreturnrunCommand(substcmd)defun 阅读全文
posted @ 2011-03-22 21:04 iTech 阅读(1189) 评论(0) 推荐(0) 编辑
摘要: 清除指定目录下的子文件, 只保留与给定的正则表达式匹配且最后创建的N个。代码:importosimportsysimportreimportshutildefcleanUp(dir,regrex,num):ifnotos.path.exists(dir)andnotos.path.isdir(dir):print'path%sisnotexistedorisnotadirectory'%dirreturnFalsesubfolderdict={}forsubIinos.listdir(dir):sf=os.path.join(dir,subI)ifos.path.isdir(s 阅读全文
posted @ 2011-03-22 18:36 iTech 阅读(2133) 评论(0) 推荐(0) 编辑
摘要: 用来copy文件和目录,当文件或文件夹已经存在时,自动增加.r1,.r2......来重命名新copy的文件。 代码:importosimportsysimportshutildefcopyWithRename(source,dest,rename=True):ifos.path.exists(dest)andrename==True:dir,name=os.path.split(dest)newdest=destifos.path.isfile(dest):namewithoutext,ext=os.path.splitext(name)i=1while(1):newdest=os.path 阅读全文
posted @ 2011-03-22 18:09 iTech 阅读(1875) 评论(1) 推荐(0) 编辑