diff --git a/remove-orphan-swddrw/README.md b/remove-orphan-swddrw/README.md new file mode 100644 index 0000000000000000000000000000000000000000..947b114ad7c5c2272dfde751e6da27b61959d30c --- /dev/null +++ b/remove-orphan-swddrw/README.md @@ -0,0 +1,6 @@ +# usage + +run this program in a directory. This directory contains some SLDPRT, SLDASM, and SLDDRW files. + +for every SLDDRW file, if there is no corresponding SLDPRT/SLDASM file (with the same filename), the SLDDRW file would be deleted. + diff --git a/remove-orphan-swddrw/main.py b/remove-orphan-swddrw/main.py new file mode 100644 index 0000000000000000000000000000000000000000..528ed60f27efa1cf5bb1cd65cc18598ba08b34c0 --- /dev/null +++ b/remove-orphan-swddrw/main.py @@ -0,0 +1,46 @@ +#!/usr/bin/env python3 +# A script to deal with product sheet. (see test-*.csv) +import traceback +def show_exception_and_exit(exc_type, exc_value, tb): + traceback.print_exception(exc_type, exc_value, tb) + input("按回车键退出") + sys.exit(-1) + +import sys +import os +if os.name == 'nt': + sys.excepthook = show_exception_and_exit + + +######################################################################### + +import os, shutil + +def main(): + print("DEBUG: workdir=", os.getcwd()) + is_drw = lambda fname: fname.lower().endswith('.slddrw') + is_prt_asm = lambda fname: (fname.lower().endswith('.sldprt') or fname.lower().endswith('.sldasm')) + files = [f for f in os.listdir('.') if os.path.isfile(f)] + filesl = [f.lower() for f in os.listdir('.') if os.path.isfile(f)] + for f in files: + if is_drw(f): + print("CHECKING ", f) + + ext_len = len('.slddrw') + expecting1 = f[:-ext_len] + '.sldprt' + expecting2 = f[:-ext_len] + '.sldasm' + if expecting1.lower() in filesl or expecting2.lower() in filesl: + # good + pass + else: + # delete this file + print("DELETE ", f) + os.remove(f) + + +main() +input("按回车键退出") + + + +