本文實例講述了Python編程實現刪除VC臨時文件及Debug目錄的方法。分享給大家供大家參考,具體如下:
# *_* coding=gb2312 *-*import osimport os.pathimport shutilinvalidFileExtList =[".ncb",".user"]invalidDirectory=["Debug"]def InternalDeleteInvalidFile(str): bFlag=False if os.path.isdir(str): basename =os.path.basename(str) for dir in invalidDirectory: if basename == dir: bFlag = True break if bFlag: shutil.rmtree(str,True) print "we are deleting ",str else: WalkDirectory(str) else: tup = os.path.splitext(str) for ext in invalidFileExtList: if tup[1] == ext: os.remove(str) print str breakdef WalkDirectory(str): fileList =os.listdir(str) for xxx in fileList: InternalDeleteInvalidFile(str+"http://"+xxx)def DeleteInvalidFile(): str = os.getcwd() print str InternalDeleteInvalidFile(str) print "hello world"if __name__ =='__main__': DeleteInvalidFile()
更多關于Python相關內容感興趣的讀者可查看本站專題:《Python文件與目錄操作技巧匯總》、《Python文本文件操作技巧匯總》、《Python URL操作技巧總結》、《Python圖片操作技巧總結》、《Python數據結構與算法教程》、《Python Socket編程技巧總結》、《Python函數使用技巧總結》、《Python字符串操作技巧匯總》及《Python入門與進階經典教程》
希望本文所述對大家Python程序設計有所幫助。
新聞熱點
疑難解答