Created
July 15, 2019 20:33
-
-
Save hidsh/9efabd1c8d62753f23cf148a27c4f9f5 to your computer and use it in GitHub Desktop.
changing filename of gerber files
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/python | |
# changing filename of gerber files | |
# usage: | |
# $ cd GERBER-FOLDER | |
# $ kicad-rename.py | |
# | |
# equivalent to following commands: | |
# mv hoge-F_Cu.gtl hoge.gtl | |
# mv hoge-F_Mask.gts hoge.gts | |
# mv hoge-F_SilkS.gto hoge.gto | |
# mv hoge-B_Cu.gbl hoge.gpl | |
# mv hoge-B_Mask.gbs hoge.gbs | |
# mv hoge-B_SilkS.gbo hoge.gbo | |
# mv hoge.drl hoge.txt | |
# mv hoge-Eco2_User.gbr hoge.gko | |
import sys, os, re | |
before = ["gtl", "gts", "gto", "gbl", "gbs", "gbo", "drl", "gbr"] | |
after = ["gtl", "gts", "gto", "gbl", "gbs", "gbo", "txt", "gko"] | |
path = os.getcwd() | |
contents = os.listdir(path) | |
files = [f for f in contents if os.path.isfile(f)] | |
i = 0 | |
for f in files: | |
extf = os.path.splitext(f)[1][1:] | |
if before.count(extf) > 0: | |
idx = before.index(extf) | |
ext = before[idx] | |
m = re.match(r"([^-]+)[-]*(.+)*\." + ext, f) | |
if m: | |
name = m.group(1) | |
fnew = name + "." + after[idx] | |
os.rename(f, fnew) | |
print(" %s --> %s" % (f, fnew)) | |
i += 1 | |
if i > 0: | |
print("%d files renamed." % i) | |
else: | |
print("nothing to do.") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment