[Tutor] (no subject)

Dave Angel d at davea.name
Sun Aug 19 21:53:31 CEST 2012


On 08/19/2012 03:29 PM, Selby Rowley Cannon wrote:
> OK, I have some code, and it uses glob.glob('*.py') to find all the
> python files in the current directory.
> Just thought i'd ask, would:
>
> glob.glob('C:\*.py') (Windows), or
>
> glob.glob('/*.py') (*nix)
>
> find all the python files on the system? Thanks

See   http://docs.python.org/library/glob.html

I don't see anywhere it implies that more than one directory would be
scanned.  In any case, it's pretty quick to just try it in the
interpreter.  I tried using python 2.7 on Linux, and it does not descend
recursively into subdirectories.

Perhaps you want os.walk, which lets you loop over an entire tree of
files/directories.

BTW, you forgot to double the backslash in your Windows example.  Either
double the backslash, or make it a raw string, or use forward slashes.


-- 

DaveA




More information about the Tutor mailing list