点击(此处)折叠或打开
- #!/usr/bin/env python3
- # _*_coding:utf–8_*_
- # Auth by raysuen
- import os,sys
- def ForceRMDir(DirName):
- ret = 0
- try:
- os.rmdir(os.path.abspath(DirName))
- except FileNotFoundError as e:
- print(e)
- ret = 1
- except OSError as e:
- for i in os.listdir(os.path.abspath(DirName)):
- if os.path.isfile(“%s/%s”%(os.path.abspath(DirName),i)):
- os.remove(“%s/%s”%(os.path.abspath(DirName),i))
- else:
- ForceRMDir(“%s/%s”%(os.path.abspath(DirName),i))
- except Exception as e:
- print(e)
- return 2
- finally:
- if ret == 0:
- os.rmdir(os.path.abspath(DirName))
- return ret