Last active
August 29, 2015 14:04
-
-
Save nicholastjohnson/8f0be512821c8e646e60 to your computer and use it in GitHub Desktop.
Recursively remove or replace unwanted characters from filenames in a directory using Python
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 | |
paths = (os.path.join(root, filename) | |
for root, _, filenames in os.walk('C:\FolderName') | |
for filename in filenames) | |
for path in paths: | |
# the '#' in the example below will be replaced by the '-' in the filenames in the directory | |
newname = path.replace('#', '-') | |
if newname != path: | |
os.rename(path, newname) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment