Staging
v0.5.0
https://github.com/python/cpython
Raw File
Tip revision: 4ce90b3a994e3eef18e43ac5a1f6c9acd0b16b8c authored by cvs2svn on 30 May 2003, 20:57:36 UTC
This commit was manufactured by cvs2svn to create tag 'r223'.
Tip revision: 4ce90b3
rmpyc.py
# Remove all the .pyc and .pyo files under ../Lib.

def deltree(root):
    import os
    def rm(path):
        os.unlink(path)
    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"):
                npyc += 1
                rm(full)
            elif short.endswith(".pyo"):
                npyo += 1
                rm(full)
    return npyc, npyo

npyc, npyo = deltree("../Lib")
print npyc, ".pyc deleted,", npyo, ".pyo deleted"
back to top