Last active
December 29, 2015 04:19
-
-
Save vasc/7613649 to your computer and use it in GitHub Desktop.
Clean filenames recursevely
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 | |
import os.path | |
import re | |
for dirpath, dirnames, filenames in os.walk('.'): | |
print dirpath | |
for dirname in dirnames: print dirname | |
for filename in filenames: | |
new_filename = filename | |
new_filename = re.sub(r'\s*-\s*', '-', new_filename) | |
new_filename = re.sub(r'-(\d\d)x(\d\d)-', r'.S\1E\2.', new_filename) | |
new_filename = re.sub(r'[\s\,\+]+', '.', new_filename) | |
new_filename = re.sub(r'\.+', '.', new_filename) | |
new_filename = re.sub(r'Season.(\d).Episode.(\d\d)', r'S0\1E\2', new_filename) | |
os.rename(os.path.join(dirpath, filename), os.path.join(dirpath, new_filename)) | |
print os.path.join(dirpath, new_filename) | |
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
curl -o /tmp/clean_file_names.py "https://gist.github.com/vasc/7613649/raw/clean_file_names.py" 2> /dev/null && python /tmp/clean_file_names.py |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment