Created
August 24, 2011 15:18
-
-
Save kyl191/1168294 to your computer and use it in GitHub Desktop.
Renamer ":" from folder/file names for Windows compatibilty
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
import os, sys, re, shutil | |
from os.path import join | |
os.chdir(sys.argv[1]) | |
# Walk the directory structure looking for folders/files with a ":" in the name | |
for root, subfolders, files in os.walk('.'): | |
for foldername in subfolders: | |
if re.search(":",foldername,re.IGNORECASE): | |
print "Renaming ", foldername , " -> ", foldername.replace(":","-") | |
newname = foldername.replace(":","-") | |
shutil.move(os.path.join(root,foldername), os.path.join(root,newname)) | |
for filename in files: | |
if re.search(":",filename,re.IGNORECASE): | |
print "Renaming ", filename , " -> ", filename.replace(":","-") | |
newname = filename.replace(":","-") | |
shutil.move(os.path.join(root,filename), os.path.join(root,newname)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment