Looping through files in a directory

r0g aioe.org at technicalbloke.com
Thu Nov 11 01:25:31 EST 2010


On 11/11/10 06:23, Chris Rebert wrote:
> On Wed, Nov 10, 2010 at 10:11 PM, r0g<aioe.org at technicalbloke.com>  wrote:
>> On 11/11/10 00:17, Steve Holden wrote:
>>> On 11/10/2010 5:46 PM, Matty Sarro wrote:
>>>>
>>>> Short story - I have a few thousand files in a directory I need to parse
>>>> through. Is there a simple way to loop through files? I'd like to avoid
>>>> writing a python script that can parse 1 file, and have to call it a few
>>>> thousand times from a bash script. Any input or pointers to functions
>>>> that'd help would be very much appreciated. Thanks!
>>>>
>>> from glob import glob
>>> for filename in glob("*"):
>>>    # do something with filename
>>>
>>> regards
>>>   Steve
>>
>> Ooo, that's nice, would that work on non *nix platforms too?
>
> Well, yeah; note the lack of any "Availability:" restriction note in
> the module's docs.
> http://docs.python.org/library/glob.html
>
> Cheers,
> Chris


Ahh, I see (or rather I don't). I'm afraid I have a habit of missing 
things that aren't there, my bad.

Roger



More information about the Python-list mailing list