Skip to content

Instantly share code, notes, and snippets.

@NO-ob
Created March 25, 2020 21:50
Show Gist options
  • Save NO-ob/ca340598c2cd8a88fd1f56f24793f071 to your computer and use it in GitHub Desktop.
Save NO-ob/ca340598c2cd8a88fd1f56f24793f071 to your computer and use it in GitHub Desktop.
Increment 3 digit number in filename by 2
import os
import re
dir = os.getcwd()
for filename in os.listdir(dir):
match = re.search("\s\d{3}\s", filename)
if match:
num = int(match.group().strip(" ")) + 2
if num < 100:
num = "0" + str(num)
newName = re.split("\s\d{3}\s",filename)[0] + " " + str(num)+ " " + re.split("\s\d{3}\s",filename)[1]
os.rename(filename,newName)
print("Renamed: "+filename+" --> "+newName)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment