[Tutor] (no subject)- finding/deleting files

akleider at sonic.net akleider at sonic.net
Sun Aug 19 23:19:47 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

Selby,

Also there is no rule that says that all python files must end in .py.
Those that don't of course will not be 'found.' ;-(

I just happened to knock out a little script that might be easily adapted
to what you want to do.  I'll attach it in case you want to make use of
it.

alex

>
> 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
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>


-------------- next part --------------
A non-text attachment was scrubbed...
Name: trash.py
Type: text/x-python
Size: 870 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/tutor/attachments/20120819/23997710/attachment.py>


More information about the Tutor mailing list