Skip to content

Instantly share code, notes, and snippets.

@Pullusb
Created October 14, 2015 13:58
Show Gist options
  • Save Pullusb/c4c52eb4da4fd29f5e68 to your computer and use it in GitHub Desktop.
Save Pullusb/c4c52eb4da4fd29f5e68 to your computer and use it in GitHub Desktop.
python utils file sequence checker
import os, re
#sequence checker, print gaps in a numberred img/files sequence in current working directory
l = [f for f in os.listdir(os.getcwd()) if not f.endswith('.py')]
miss = 0
gap = 0
i = 0
for f in l:
num = re.search('^(.*?)(\d+)(\D*)$', l[i])
num = int(num.group(2))
if i:
prev = re.search('^(.*?)(\d+)(\D*)$', l[i-1])
prev = int(prev.group(2))
res = num - prev
if res > 1:
gaplength = res - 1
miss += gaplength
gap += 1
if res == 2:
print ("gap {}".format(num - 1, gaplength))
else:
print ("gap {0} - {1} : {2} files".format(prev+1, num-1, gaplength))
i += 1
if gap:
print (gap, 'gap found')
print (miss, "total missing")
print("finished :", i, "scanned")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment