python递归删除指定目录

2015-06-18 0 257
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()

遇见资源网 python python递归删除指定目录 http://www.ox520.com/15535.html

常见问题

相关文章

发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务