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 | 6a9aec4 | 2001-02-11 00:46:39 +0000 | [diff] [blame] | 3 | def deltree(root): |
| 4 | import os |
| 5 | def rm(path): |
| 6 | os.unlink(path) |
| 7 | npyc = npyo = 0 |
| 8 | dirs = [root] |
| 9 | while dirs: |
| 10 | dir = dirs.pop() |
| 11 | for short in os.listdir(dir): |
| 12 | full = os.path.join(dir, short) |
| 13 | if os.path.isdir(full): |
| 14 | dirs.append(full) |
| 15 | elif short.endswith(".pyc"): |
| 16 | npyc += 1 |
| 17 | rm(full) |
| 18 | elif short.endswith(".pyo"): |
| 19 | npyo += 1 |
| 20 | rm(full) |
| 21 | return npyc, npyo |
| 22 | |
| 23 | npyc, npyo = deltree("../Lib") |
| 24 | print npyc, ".pyc deleted,", npyo, ".pyo deleted" |