Skip to content

Instantly share code, notes, and snippets.

@geryxyz
Created April 6, 2019 20:25
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 geryxyz/030d5b466a2a9f7409b9776cc98a313a to your computer and use it in GitHub Desktop.
Save geryxyz/030d5b466a2a9f7409b9776cc98a313a to your computer and use it in GitHub Desktop.
Setting speed for CNC *.tap file in a banch, it will change all F instruction with the new specified speed and create a new file. It scan the current working directory and will process all *.tap expect the results of previous execution.
import sys
import re
import glob
import os.path
import pdb
speed = int(sys.argv[1])
files = glob.glob("*.tap")
for original in files:
exts = os.path.splitext(original)
if re.search(r'F\d+$', exts[0]):
print("skipping file: %s" % original)
else:
new = '%s.F%d.tap' % (exts[0], speed)
print(original + " --> " + new)
with open(original, 'r') as in_file, open(new, 'w') as out_file:
for line in in_file:
if re.search(r'F\d+', line):
new_line = re.sub(r'F\d+', 'F%d' % speed, line)
out_file.write(new_line)
else:
out_file.write(line)
@geryxyz
Copy link
Author

geryxyz commented Mar 7, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment