[Tutor] Scan Directory for files

Steve Poe steve.poe at gmail.com
Sat Aug 2 09:00:23 CEST 2008


Fred,

What is/are the exact error message(s)?

You may want to look at the module glob.

Steve



Ar e you typing this in the python interpreter or
On Aug 1, 2008, at 10:41 PM, Fred @ Mac wrote:

> Hello,
>
> new to python, so please go easy on me!
>
> I am using
>
> for f in os.listdir(watch_dir):
>        tree = ET.parse(f)
>        for shot in tree.findall('Shot'):
> 		..do stuff..
>
> to scan a directory for specific files (xml files specifically).
>
> But my script fails if, for example, a directory also exists in  
> "watch_dir"
>
> How can i restructure this so it only returns a list of the .xml  
> files in that directory, ignores other files and or directories in  
> "watch_dir"
>
> Thanks!
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor



More information about the Tutor mailing list