Tim Peters | 6a9aec4 | 2001-02-11 00:46:39 +0000 | [diff] [blame] | 1 | # Remove all the .pyc and .pyo files under ../Lib. |
2 | |||||
Tim Peters | 8b7beb6 | 2003-04-26 00:53:24 +0000 | [diff] [blame] | 3 | |
Tim Peters | 6a9aec4 | 2001-02-11 00:46:39 +0000 | [diff] [blame] | 4 | def deltree(root): |
5 | import os | ||||
Tim Peters | 8b7beb6 | 2003-04-26 00:53:24 +0000 | [diff] [blame] | 6 | from os.path import join |
7 | |||||
Tim Peters | 6a9aec4 | 2001-02-11 00:46:39 +0000 | [diff] [blame] | 8 | npyc = npyo = 0 |
Tim Peters | 8b7beb6 | 2003-04-26 00:53:24 +0000 | [diff] [blame] | 9 | for root, dirs, files in os.walk(root): |
10 | for name in files: | ||||
11 | delete = False | ||||
12 | if name.endswith('.pyc'): | ||||
13 | delete = True | ||||
Tim Peters | 6a9aec4 | 2001-02-11 00:46:39 +0000 | [diff] [blame] | 14 | npyc += 1 |
Tim Peters | 8b7beb6 | 2003-04-26 00:53:24 +0000 | [diff] [blame] | 15 | elif name.endswith('.pyo'): |
16 | delete = True | ||||
Tim Peters | 6a9aec4 | 2001-02-11 00:46:39 +0000 | [diff] [blame] | 17 | npyo += 1 |
Tim Peters | 8b7beb6 | 2003-04-26 00:53:24 +0000 | [diff] [blame] | 18 | |
19 | if delete: | ||||
20 | os.remove(join(root, name)) | ||||
21 | |||||
Tim Peters | 6a9aec4 | 2001-02-11 00:46:39 +0000 | [diff] [blame] | 22 | return npyc, npyo |
23 | |||||
24 | npyc, npyo = deltree("../Lib") | ||||
Thomas Heller | 9abb963 | 2007-07-11 09:41:23 +0000 | [diff] [blame] | 25 | print(npyc, ".pyc deleted,", npyo, ".pyo deleted") |