点击(此处)折叠或打开
- #!/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
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/28572479/viewspace-2157561/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/28572479/viewspace-2157561/