Staging
v0.5.1
https://github.com/python/cpython
Revision 6db12839922383398b0035446723a8d78bf86393 authored by Neal Norwitz on 11 October 2002, 21:55:13 UTC, committed by Neal Norwitz on 11 October 2002, 21:55:13 UTC
1 parent 3974ce3
Raw File
Tip revision: 6db12839922383398b0035446723a8d78bf86393 authored by Neal Norwitz on 11 October 2002, 21:55:13 UTC
Backport 2.34. SF #621948, update docstring for md5 by David M. Cooke
Tip revision: 6db1283
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