Skip to content

Instantly share code, notes, and snippets.

@sneal
Created June 5, 2023 04:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sneal/fc51bcf1d0db07cb45edc889be6a5ab8 to your computer and use it in GitHub Desktop.
Save sneal/fc51bcf1d0db07cb45edc889be6a5ab8 to your computer and use it in GitHub Desktop.
Script to rename all GoPro generated media in a directory to an ordinal number series (i.e. human understandable)
import sys, os
from pathlib import Path
from operator import itemgetter
p = ''.join(sys.argv[1:])
if len(p) == 0:
print('you must give a fully qualified directory path to process')
exit()
files = list(Path(p).glob('*.MP4'))
if len(files) == 0:
print('did not find any mp4 files')
exit()
vids = []
for file in files:
f = Path(file).stem
if not f.startswith("GX"):
print('expected filename to start with GX, but got {}'.format(f))
exit()
vids.append((
f + '.MP4',
int(f[2:4]),
int(f[4:])
))
# sort by last number (series) then first number (order within series)
vids.sort(key=itemgetter(2,1))
for i, v in enumerate(vids):
src = os.path.join(p, v[0])
dest = os.path.join(p, str(i + 1) + '.MP4')
print('{} => {}'.format(src, dest))
os.rename(src, dest)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment