六、python小功能记录——递归删除bin和obj内文件

删除C#生成的bin和obj内文件。

import os

path= os.getcwd()
print('当前路径:'+ path)

def finddir(file_dir):
    for dirs in os.listdir(file_dir):
        pathname = os.path.join(file_dir, dirs)
        if(os.path.isdir(pathname)):
             if('\obj' in pathname or '\bin' in pathname):
                 delete(pathname)
             else:
                 finddir(pathname)
                
def delete(path):
    for dirs in os.listdir(path):
        pathname2 = os.path.join(path, dirs)
        if (os.path.isfile(pathname2)):
            os.remove(pathname2)
        else:
            delete(pathname2)
    #os.removedirs(path)
        
finddir(path)

input('输入任何键关闭')
原文地址:https://www.cnblogs.com/cvol/p/10910881.html