Skip to content

Instantly share code, notes, and snippets.

@haradreborn
Created December 5, 2014 08:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save haradreborn/9c68ce462262f95f7d35 to your computer and use it in GitHub Desktop.
Save haradreborn/9c68ce462262f95f7d35 to your computer and use it in GitHub Desktop.
clear directory
def file_clear(self, dir):
retry = True
while retry:
try:
retry = False
if (os.name == "nt"):
try:
shutil.rmtree(dir)
except exceptions.WindowsError, e:
if e.winerror == 5: # No write permission
win32api.SetFileAttributes(dir, win32con.FILE_ATTRIBUTE_NORMAL)
retry = True
else:
shutil.rmtree(dir)
if not os.path.exists(dir):
os.makedirs(dir)
except Exception:
print(traceback.format_exc())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment