blob: a1e75bb7ae5b4ba1706f47c7b373da9763f11243 [file] [log] [blame]
Tim Peters6a9aec42001-02-11 00:46:39 +00001# Remove all the .pyc and .pyo files under ../Lib.
2
Tim Peters8b7beb62003-04-26 00:53:24 +00003
Tim Peters6a9aec42001-02-11 00:46:39 +00004def deltree(root):
5 import os
Tim Peters8b7beb62003-04-26 00:53:24 +00006 from os.path import join
7
Tim Peters6a9aec42001-02-11 00:46:39 +00008 npyc = npyo = 0
Tim Peters8b7beb62003-04-26 00:53:24 +00009 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 Peters6a9aec42001-02-11 00:46:39 +000014 npyc += 1
Tim Peters8b7beb62003-04-26 00:53:24 +000015 elif name.endswith('.pyo'):
16 delete = True
Tim Peters6a9aec42001-02-11 00:46:39 +000017 npyo += 1
Tim Peters8b7beb62003-04-26 00:53:24 +000018
19 if delete:
20 os.remove(join(root, name))
21
Tim Peters6a9aec42001-02-11 00:46:39 +000022 return npyc, npyo
23
24npyc, npyo = deltree("../Lib")
Thomas Heller9abb9632007-07-11 09:41:23 +000025print(npyc, ".pyc deleted,", npyo, ".pyo deleted")