Last active
August 28, 2021 10:59
-
-
Save aweffr/d7d733f6c09c8cd12f1bbcd9559c35d0 to your computer and use it in GitHub Desktop.
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
# rename.py | |
# usage: python3 rename.py ~/pics | |
import sys | |
from pathlib import Path | |
def print_usage(): | |
print('usage: python3 rename.py [target-dir]', file=sys.stderr) | |
def main(): | |
if len(sys.argv) != 2: | |
print_usage() | |
exit(-1) | |
dir_ = Path(sys.argv[1]) | |
if not dir_.exists(): | |
print(f'{sys.argv[1]} not exist', file=sys.stderr) | |
exit(-1) | |
files_to_rename = [] | |
for file in dir_.rglob('*.JPG'): | |
print('plan to rename file:', file) | |
files_to_rename.append(file) | |
ret = input('press \'y\' to continue:') | |
if ret.strip() not in ['y', 'Y']: | |
exit(0) | |
for file in files_to_rename: | |
new_file = file.parent / (file.name.replace('.JPG', '.jpg')) | |
file.rename(new_file) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment