Created
January 12, 2020 04:34
-
-
Save fengye/b936f331f621d875e66c71c90904b6c7 to your computer and use it in GitHub Desktop.
Rename All Files to Lowercase Recursively
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
#!/usr/bin/python3 | |
import os | |
from pathlib import Path | |
import argparse | |
if __name__ == "__main__": | |
parser = argparse.ArgumentParser() | |
parser.add_argument('directory', metavar='D', help='The working directory') | |
args = parser.parse_args() | |
for filename in Path(args.directory).rglob('*'): | |
path = os.path.dirname(filename) | |
only_filename = os.path.basename(filename) | |
new_filename = only_filename.replace(' ', '-').lower() | |
print(os.path.join(path, only_filename) + " -> " + os.path.join(path, new_filename)) | |
os.rename(os.path.join(path, only_filename), os.path.join(path, new_filename)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment