Commit 8b7beb63 authored by Tim Peters's avatar Tim Peters

Use os.walk() to find files to delete.

parent 2f36b3e2
# Remove all the .pyc and .pyo files under ../Lib. # Remove all the .pyc and .pyo files under ../Lib.
def deltree(root): def deltree(root):
import os import os
def rm(path): from os.path import join
os.unlink(path)
npyc = npyo = 0 npyc = npyo = 0
dirs = [root] for root, dirs, files in os.walk(root):
while dirs: for name in files:
dir = dirs.pop() delete = False
for short in os.listdir(dir): if name.endswith('.pyc'):
full = os.path.join(dir, short) delete = True
if os.path.isdir(full):
dirs.append(full)
elif short.endswith(".pyc"):
npyc += 1 npyc += 1
rm(full) elif name.endswith('.pyo'):
elif short.endswith(".pyo"): delete = True
npyo += 1 npyo += 1
rm(full)
if delete:
os.remove(join(root, name))
return npyc, npyo return npyc, npyo
npyc, npyo = deltree("../Lib") npyc, npyo = deltree("../Lib")
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment