Skip to content

Instantly share code, notes, and snippets.

@jonchun
Created March 28, 2020 18:24
Show Gist options
  • Save jonchun/c4716633f9ce82d6367f81a04925f01d to your computer and use it in GitHub Desktop.
Save jonchun/c4716633f9ce82d6367f81a04925f01d to your computer and use it in GitHub Desktop.
recursively change names to all lowercase and replace spaces with _
import glob
from pathlib import Path
file_list = glob.glob('**/*', recursive=True)
file_list.sort(key=len, reverse=True)
def rename(file):
_name = file.name.replace(' ', '_').lower()
_name = file.parent / Path(_name)
file.rename(_name)
for file in file_list:
if file == __file__:
continue
_file = Path(file)
rename(_file)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment