Skip to content

Instantly share code, notes, and snippets.

@humanfactors
Created November 20, 2017 06:37
Show Gist options
  • Save humanfactors/f682e42500072407ad1f4e5f80034f54 to your computer and use it in GitHub Desktop.
Save humanfactors/f682e42500072407ad1f4e5f80034f54 to your computer and use it in GitHub Desktop.
atc file renaming
import os
import re
PINFO = re.compile(r"data/PID_(.*?)/Day\ (1|2)")
BP = re.compile(r"RandomBullpup_(\d).xml\.(csv|log)")
FN = re.compile(r"EXP3_AltFixFinland_Day(1|2)_Fix_PID-(\w{1,5})\.xml\.(csv|log)")
for root, dirs, files in os.walk("data/"):
for file in files:
day = PINFO.search(root).group(2)
pid = PINFO.search(root).group(1)
if "finland" in str.lower(file) and file.endswith(("log", "csv")):
fday = FN.search(file).group(1)
fpid = FN.search(file).group(2)
ext = FN.search(file).group(3)
newfilename = "EXP3-FINLAND-P%s-DAY%s" % (pid, day)
print(newfilename + os.extsep + ext)
os.rename(root + os.sep + file, root + os.sep + newfilename + os.extsep + ext)
elif "bullpup" in str.lower(file):
bp = BP.search(file).group(1)
ext = BP.search(file).group(2)
newfilename = "EXP3-BULLPUP%s-P%s-DAY%s" % (bp, pid, day)
os.rename(root + os.sep + file, root + os.sep + newfilename + os.extsep + ext)
# EXP3-BULLPUP1-P38-DAY1.csv
# EXP3-BULLPUP7-P38-DAY1.log
# EXP3-FINLAND-P38-DAY1.log
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment