Created
July 6, 2017 19:48
-
-
Save dpwrussell/64cc918a731598e43c88ef63b71f2d87 to your computer and use it in GitHub Desktop.
AT File Renaming
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
#!/usr/bin/env python3 | |
import os | |
import re | |
r = re.compile(r'(\w\s-\s\d\d\(fld\s\d\swv\s\w+\s-\s[\w]+-\stime)(\s\d+)(\s-\s\d+\sms)(\)\.tif)') | |
d = os.path.abspath('files/') | |
all_files = [f for f in os.listdir(d) if os.path.isfile(os.path.join(d, f))] | |
matching = 0 | |
for f in all_files: | |
m = r.match(f) | |
if m: | |
matching += 1 | |
os.rename( | |
os.path.join(d, f), | |
os.path.join(d, '{}{:03}{}'.format(m.group(1), int(m.group(2)) + 4, m.group(4))) | |
) | |
if matching % 1000 == 0: | |
print("Completed renaming {} files".format(matching)) | |
print("Renaming count", matching) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment