python遞歸刪除指定目錄

mxw8 9年前發布 | 979 次閱讀 Python

'''
@author: Administrator
'''

coding=utf-8

import os import shutil dir = "G://tmp//sz//ngtsverify"

def removeDir(): for root, dirs, files in os.walk(dir, True, None, False): if 'CVS' in root: print("the root is: ", root) files = os.listdir(root) for f in files: if (os.path.isfile(os.path.join(root,f)) == True): print('the file name is:', os.path.splitext(os.path.join(root,f))[0])

                 #刪除文件
                 os.remove(os.path.join(root,f))
         #刪除主目錄       
         os.removedirs(root)



if name == 'main': removeDir()</pre>

 本文由用戶 mxw8 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!