Python 删除目录下文件,python目录,import osimp
文章由Byrx.net分享于2019-03-23 07:03:22
Python 删除目录下文件,python目录,import osimp
import osimport shutildef CleanDir( Dir ): if os.path.isdir( Dir ): paths = os.listdir( Dir ) for path in paths: filePath = os.path.join( Dir, path ) if os.path.isfile( filePath ): try: os.remove( filePath ) except os.error: autoRun.exception( "remove %s error." %filePath )#引入logging elif os.path.isdir( filePath ): if filePath[-4:].lower() == ".svn".lower(): continue shutil.rmtree(filePath,True) return TrueDir = "D:\\\\Temp"CleanDir(Dir)#该片段来自于http://byrx.net
评论关闭