Created
March 7, 2019 01:18
-
-
Save akanik/4710f8e517f760ac193901b14e21547f to your computer and use it in GitHub Desktop.
Lowercase and slugify filenames
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
# works with python3 and python2 | |
from slugify import slugify | |
import os | |
directory = 'all-lower/' | |
for old_filename in os.listdir(directory): | |
old_filename_pieces = os.path.splitext(old_filename) | |
#optional: if you only want to change a certain filetype | |
#if old_filename_pieces[1] == '.csv': | |
old_filepath = directory + old_filename | |
clean_filename = slugify(old_filename_pieces[0]) + old_filename_pieces[1] | |
clean_filepath = directory + clean_filename | |
os.rename(old_filepath,clean_filepath) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment