Skip to content

Instantly share code, notes, and snippets.

@TETRA2000
Created February 3, 2014 02:42
Show Gist options
  • Select an option

  • Save TETRA2000/8778140 to your computer and use it in GitHub Desktop.

Select an option

Save TETRA2000/8778140 to your computer and use it in GitHub Desktop.
Windowsで削除出来ない深いディレクトリツリーを削除する
#test.py
import os
import shutil
import random
while True:
dir_list = os.listdir('.')
for d in dir_list:
if not os.path.isdir(d):
if not d=='test.py':
os.remove(d)
continue
subdir_list = os.listdir(d)
for subd in subdir_list:
print subd
newname = str(random.randint(0, 100000000))
while os.path.exists(newname):
newname = str(random.randint(0, 100000000))
os.rename(d+'\\'+subd, '.\\' + newname)
try:
os.rmdir(d)
break
except Exception, e:
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment