Skip to content

Instantly share code, notes, and snippets.

@david-wm-sanders
Created February 21, 2016 16:02
Show Gist options
  • Save david-wm-sanders/7959d55279bfb8feba24 to your computer and use it in GitHub Desktop.
Save david-wm-sanders/7959d55279bfb8feba24 to your computer and use it in GitHub Desktop.
Renames DSC_x.JPG to DSC_x+999.JPG to reorder pictures when a new folder has been created after DSC_0999.JPG and the pictures in the new folder start from DSC_0001.JPG again.
#!/usr/bin/env python3
import os
import sys
from shutil import copy2
from pathlib import Path
if len(sys.argv) != 2:
raise Exception("Invalid number of arguments. One directory path must be provided.")
p = Path(sys.argv[1])
if not p.exists():
raise Exception("Specified path does not exist.")
pictures = p.glob("*.JPG")
if pictures:
od = p / "recounted/"
if not od.exists():
os.mkdir(str(od))
for picture in pictures:
name = picture.name
number = int(name[4:8])
o = p / "recounted/DSC_{0}.JPG".format(number + 999)
copy2(str(picture), str(o))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment