find function
Mark McEahern
mark at mceahern.com
Sun Jan 25 17:51:24 EST 2004
On Sun, 2004-01-25 at 16:25, Uwe Mayer wrote:
> Hi,
>
> is there for python a find() function, like the perl module Find or the
> command line tool find?
Try:
import glob
pattern = '*.pyc'
for name in glob.glob(pattern):
print name
glob's not recursive, though. For that, consider os.walk:
import os
path = '.'
extensions = ('.pyc',)
for root, dirs, files in os.walk(path):
for name in files:
prefix, ext = os.path.splitext(name)
if ext not in extensions:
continue
fullname = os.path.join(root, name)
print fullname
The above code may have syntax errors since I didn't run it.
// m
More information about the Python-list
mailing list