Skip to content

Instantly share code, notes, and snippets.

@dpwrussell
Created July 6, 2017 19:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dpwrussell/64cc918a731598e43c88ef63b71f2d87 to your computer and use it in GitHub Desktop.
Save dpwrussell/64cc918a731598e43c88ef63b71f2d87 to your computer and use it in GitHub Desktop.
AT File Renaming
#!/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