Fix comment.
[python.git] / Mac / scripts / zappycfiles.py
bloba8193c1206a5a6bd4419a0e7dfb0012b7a97dc68
1 #!/usr/local/bin/python
2 """Recursively zap all .pyc and .pyo files"""
3 import os
4 import sys
6 # set doit true to actually delete files
7 # set doit false to just print what would be deleted
8 doit = 1
10 def main():
11 if not sys.argv[1:]:
12 if os.name == 'mac':
13 import EasyDialogs
14 dir = EasyDialogs.AskFolder(message='Directory to zap pyc files in')
15 if not dir:
16 sys.exit(0)
17 zappyc(dir)
18 else:
19 print 'Usage: zappyc dir ...'
20 sys.exit(1)
21 for dir in sys.argv[1:]:
22 zappyc(dir)
24 def zappyc(dir):
25 os.path.walk(dir, walker, None)
27 def walker(dummy, top, names):
28 for name in names:
29 if name[-4:] in ('.pyc', '.pyo'):
30 path = os.path.join(top, name)
31 print 'Zapping', path
32 if doit:
33 os.unlink(path)
35 if __name__ == '__main__':
36 main()