递归删除指定的目录及文件

    xiaoxiao2021-12-13  18

    # 删除文件以及文件夹 def removeDir(dirPath):     if not os.path.isdir(dirPath):         return     files = os.listdir(dirPath)     try:         for file in files:             filePath = os.path.join(dirPath, file)             if os.path.isfile(filePath):                 os.remove(filePath)             elif os.path.isdir(filePath):                 removeDir(filePath)         os.rmdir(dirPath)     except Exception, e:         print e # 删除配置文件 def deletework(outputpath): try: flag = os.path.exists(outputpath) except Exception, e: print "delete work Error !" if flag == True: removeDir(outputpath) print "deletework End !"
    转载请注明原文地址: https://ju.6miu.com/read-950155.html

    最新回复(0)