Last active
August 22, 2022 23:01
-
-
Save uonr/f24b447cb6cb401e2899ded028e52541 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
#!/usr/bin/env python3 | |
import imghdr | |
import glob | |
from sys import argv | |
from pathlib import Path | |
pattern = '/Users/uonr/Pictures/*'; | |
print(pattern) | |
for filepath in [Path(p) for p in glob.glob(pattern)]: | |
if filepath.is_dir(): | |
continue | |
with open(filepath, 'rb') as f: | |
what = imghdr.what(f) | |
if not what: | |
continue | |
rename = filepath.with_suffix('.' + what) | |
if rename == filepath: | |
continue | |
print(f'rename {filepath} -> {rename}') | |
filepath.rename(rename) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment