Created
September 7, 2025 21:15
-
-
Save tmck-code/c8363ea2fbade0ca0aa7eee1d6979f14 to your computer and use it in GitHub Desktop.
Rename GOPRO files
This file contains hidden or 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 os | |
| import sys | |
| import json | |
| from datetime import datetime | |
| import shutil | |
| def rename_gopro_files(indir: str, outdir: str, dryrun: bool=False) -> None: | |
| if not os.path.exists(outdir): | |
| os.makedirs(outdir) | |
| for root, dirs, files in os.walk(indir): | |
| fpaths = [os.path.join(root, f) for f in files] | |
| for fpath in fpaths: | |
| if not (fpath.endswith('.JPG') or fpath.endswith('.MP4')): | |
| continue | |
| st = os.stat(fpath) | |
| mod_timestamp = datetime.fromtimestamp(st.st_mtime).replace(microsecond=0).astimezone() | |
| new_fpath = os.path.join( | |
| outdir, | |
| f'{mod_timestamp.strftime("%Y%m%d_%H%M%S")}_{os.path.basename(fpath)}', | |
| ) | |
| print(f'Renaming {fpath} with ts {mod_timestamp.isoformat()} to {new_fpath}') | |
| if dryrun: | |
| continue | |
| os.rename(fpath, new_fpath) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment