Skip to content

Instantly share code, notes, and snippets.

@akanik
Created March 7, 2019 01:18
Show Gist options
  • Save akanik/4710f8e517f760ac193901b14e21547f to your computer and use it in GitHub Desktop.
Save akanik/4710f8e517f760ac193901b14e21547f to your computer and use it in GitHub Desktop.
Lowercase and slugify filenames
# 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