Last active
December 14, 2015 12:39
-
-
Save witoff/5088078 to your computer and use it in GitHub Desktop.
Recursively rename files to work nicely on NTFS.
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
import os | |
from os import path, listdir | |
bad = {'*':'_', '\\':'__'} | |
def getDirs(path): | |
return [ name for name in listdir(path) if path.isdir(path.join(thedir, name)) ] | |
def printAll(uri): | |
elements = listdir(uri) | |
#sanitize | |
for e in elements: | |
item = path.join(uri, e) | |
new_name = e | |
for c in bad: | |
new_name = new_name.replace(c, bad[c]) | |
if new_name != e: | |
print 'renaming: %s to %s' % (item, new_name) | |
#os.rename(item, path.join(uri, new_name)) | |
elements = listdir(uri) | |
# recurse | |
dirs = [d for d in elements if path.isdir(path.join(uri, d))] | |
for d in dirs: printAll(path.join(uri, d)) | |
printAll(os.getcwd()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment