Created
February 3, 2014 02:42
-
-
Save TETRA2000/8778140 to your computer and use it in GitHub Desktop.
Windowsで削除出来ない深いディレクトリツリーを削除する
This file contains hidden or 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
| #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