Created
December 5, 2014 08:52
-
-
Save haradreborn/9c68ce462262f95f7d35 to your computer and use it in GitHub Desktop.
clear directory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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