Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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.path.join(d, f),
os.path.join(d, '{}{:03}{}'.format(, int( + 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
You can’t perform that action at this time.