Jack Jansen | dfebb27 | 2001-01-23 22:45:52 +0000 | [diff] [blame] | 1 | # Zap .pyc files |
| 2 | import os |
| 3 | import sys |
| 4 | |
| 5 | doit = 1 |
| 6 | |
| 7 | def main(): |
| 8 | if os.name == 'mac': |
| 9 | import macfs |
| 10 | fss, ok = macfs.GetDirectory('Directory to zap pyc files in') |
| 11 | if not ok: |
| 12 | sys.exit(0) |
| 13 | dir = fss.as_pathname() |
| 14 | zappyc(dir) |
| 15 | else: |
| 16 | if not sys.argv[1:]: |
| 17 | print 'Usage: zappyc dir ...' |
| 18 | sys.exit(1) |
| 19 | for dir in sys.argv[1:]: |
| 20 | zappyc(dir) |
| 21 | |
| 22 | def zappyc(dir): |
| 23 | os.path.walk(dir, walker, None) |
| 24 | |
| 25 | def walker(dummy, top, names): |
| 26 | for name in names: |
| 27 | if name[-4:] == '.pyc': |
| 28 | path = os.path.join(top, name) |
| 29 | print 'Zapping', path |
| 30 | if doit: |
| 31 | os.unlink(path) |
| 32 | |
| 33 | if __name__ == '__main__': |
| 34 | main() |
| 35 | |