- import os,errno
- #基本工具类
- #①递归生成输入的路径下面的文件夹或文件
- #②递归删除输入的路径下面的文件夹及文件
- ‘‘‘
- param : dirPath
- return :
- AuthorCreated by Wu Yongcong 2017-8-17
- function:remove a input dirPath and the files/dictionary under it
- ‘‘‘
- 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 as e:
- print(e)
- ‘‘‘
- param: dirPath
- Created by Wu Yongcong 2017-8-17
- function:add a input dirPath and the files/dictionary under it
- ‘‘‘
- def mkdir_p(dirPath):
- try:
- os.makedirs(dirPath)
- except OSError as oe:
- if oe.errno == errno.EEXIST and os.path.isdir(dirPath):
- pass
- else:
- raise
时间: 2025-01-08 03:04:48