Looping through files in a directory

Steve Holden steve at holdenweb.com
Thu Nov 11 01:17:34 CET 2010


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
-- 
Steve Holden           +1 571 484 6266   +1 800 494 3119
PyCon 2011 Atlanta March 9-17       http://us.pycon.org/
See Python Video!       http://python.mirocommunity.org/
Holden Web LLC                 http://www.holdenweb.com/




More information about the Python-list mailing list