Created
March 25, 2020 21:50
-
-
Save NO-ob/ca340598c2cd8a88fd1f56f24793f071 to your computer and use it in GitHub Desktop.
Increment 3 digit number in filename by 2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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