Created
March 28, 2020 18:24
-
-
Save jonchun/c4716633f9ce82d6367f81a04925f01d to your computer and use it in GitHub Desktop.
recursively change names to all lowercase and replace spaces with _
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 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