|
|
|
@ -1,4 +1,4 @@
|
|
|
|
|
import os, json, re, shlex
|
|
|
|
|
import os, json, re, shlex, sys
|
|
|
|
|
import subprocess
|
|
|
|
|
from datetime import datetime
|
|
|
|
|
|
|
|
|
@ -124,29 +124,33 @@ def listimgs(dir):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def reorder_imgs(dir, dry):
|
|
|
|
|
# does zero pad file numbers
|
|
|
|
|
|
|
|
|
|
lsimgs = listimgs(dir)
|
|
|
|
|
for img in lsimgs:
|
|
|
|
|
img_name, img_ext = os.path.splitext(img)
|
|
|
|
|
|
|
|
|
|
print(img)
|
|
|
|
|
# does file follow \d{1,}\.img_ext
|
|
|
|
|
numb_exp = re.compile(
|
|
|
|
|
r'(?P<name>.*?)(?P<num>\d+)(?P<ext>%s)'% re.escape(img_ext))
|
|
|
|
|
match = re.search(numb_exp, img)
|
|
|
|
|
if not match:
|
|
|
|
|
print(f'Image {img} Filename is not suitable for bulk upload.'
|
|
|
|
|
f'Filename pattern does not match 1.jpg 01.jpg'
|
|
|
|
|
f'Filename pattern dn\'t match 1.jpg 01.jpg something01.jpg'
|
|
|
|
|
f'You have to DO IT MANUALLY')
|
|
|
|
|
sys.exit()
|
|
|
|
|
else:
|
|
|
|
|
# only change name of single digit numbers
|
|
|
|
|
if len(match.groupdict()['num']) == 1:
|
|
|
|
|
name = match.groupdict()['name']
|
|
|
|
|
num = match.groupdict()['num'].zfill(2) # pad with 0
|
|
|
|
|
num = match.groupdict()['num'].zfill(3) # pad with 0s
|
|
|
|
|
ext = match.groupdict()['ext']
|
|
|
|
|
new_img = name + num + ext
|
|
|
|
|
if dry == False:
|
|
|
|
|
os.rename(os.path.join(dir, img),
|
|
|
|
|
os.path.join(dir, new_img))
|
|
|
|
|
src_img = os.path.join(dir, img)
|
|
|
|
|
dst_img = os.path.join(dir, new_img)
|
|
|
|
|
print(f'Renaming: {img} >>>>> {new_img}')
|
|
|
|
|
|
|
|
|
|
if dry == False:
|
|
|
|
|
os.replace(src_img, dst_img)
|
|
|
|
|
lsimgs = listimgs(dir) # update list w/ renamed imgs
|
|
|
|
|
return listimgs(dir)
|
|
|
|
|
|
|
|
|
|