Skip to content

Instantly share code, notes, and snippets.

@uonr
Last active August 22, 2022 23:01
Show Gist options
  • Save uonr/f24b447cb6cb401e2899ded028e52541 to your computer and use it in GitHub Desktop.
Save uonr/f24b447cb6cb401e2899ded028e52541 to your computer and use it in GitHub Desktop.
#!/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