Skip to content

Instantly share code, notes, and snippets.

@kyl191
Created August 24, 2011 15:18
Show Gist options
  • Save kyl191/1168294 to your computer and use it in GitHub Desktop.
Save kyl191/1168294 to your computer and use it in GitHub Desktop.
Renamer ":" from folder/file names for Windows compatibilty
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