Skip to content

Instantly share code, notes, and snippets.

@foone
Created October 10, 2022 19:27
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 foone/980dc6e1d4bf7e6b1176014ed38bd02e to your computer and use it in GitHub Desktop.
Save foone/980dc6e1d4bf7e6b1176014ed38bd02e to your computer and use it in GitHub Desktop.
import os,glob,sys
images=glob.glob(sys.argv[1])
images.sort()
if (len(images)&1) == 1:
print("Odd number of items! Can't split")
sys.exit(1)
midpoint = len(images)//2
first_half = images[:midpoint]
last_half = images[midpoint:][::-1]
for pagenum,(image_a, image_b) in enumerate(zip(first_half,last_half)):
for image, suffix in ((image_a, 'a'), (image_b, 'b')):
_,ext=os.path.splitext(image)
os.rename(image,'renamed_{:04}{}{}'.format(pagenum,suffix,ext))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment