summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2003-04-26 00:53:24 (GMT)
committerTim Peters <tim.peters@gmail.com>2003-04-26 00:53:24 (GMT)
commit8b7beb631bd34bbc7d17e8f7e7256ee076a3e381 (patch)
tree81658b78761547a894583093ec991f079685c59e
parent2f36b3e2050dee0d622086f12ebb3502c46c54a1 (diff)
downloadcpython-8b7beb631bd34bbc7d17e8f7e7256ee076a3e381.zip
cpython-8b7beb631bd34bbc7d17e8f7e7256ee076a3e381.tar.gz
cpython-8b7beb631bd34bbc7d17e8f7e7256ee076a3e381.tar.bz2
Use os.walk() to find files to delete.
-rw-r--r--PCbuild/rmpyc.py27
1 files changed, 14 insertions, 13 deletions
diff --git a/PCbuild/rmpyc.py b/PCbuild/rmpyc.py
index 019c69b..43c8576 100644
--- a/PCbuild/rmpyc.py
+++ b/PCbuild/rmpyc.py
@@ -1,23 +1,24 @@
# Remove all the .pyc and .pyo files under ../Lib.
+
def deltree(root):
import os
- def rm(path):
- os.unlink(path)
+ from os.path import join
+
npyc = npyo = 0
- dirs = [root]
- while dirs:
- dir = dirs.pop()
- for short in os.listdir(dir):
- full = os.path.join(dir, short)
- if os.path.isdir(full):
- dirs.append(full)
- elif short.endswith(".pyc"):
+ for root, dirs, files in os.walk(root):
+ for name in files:
+ delete = False
+ if name.endswith('.pyc'):
+ delete = True
npyc += 1
- rm(full)
- elif short.endswith(".pyo"):
+ elif name.endswith('.pyo'):
+ delete = True
npyo += 1
- rm(full)
+
+ if delete:
+ os.remove(join(root, name))
+
return npyc, npyo
npyc, npyo = deltree("../Lib")