module for doing unix "find"-like things?
jeremy at jdyallop.freeserve.co.uk
Fri Apr 11 20:45:39 CEST 2003
Mark Harrison wrote:
> Is there such a thing? I didn't see such a thing, but
> "find" is not the easist thing to search for.
os.path.walk is often useful in such circumstances.
> Specifically, I would like to replace an external call to
> for i in `find $top -type l -maxdepth 1`; ...
With '-maxdepth 1' you might as well use os.listdir(). Perhaps
something like the following is what you're looking for:
top = os.getenv('top')
for i in [l for l in os.listdir(os.getenv('top'))
if os.path.islink(os.path.join(top, l))]:
More information about the Python-list