[Tutor] Scan Directory for files
Alan Gauld
alan.gauld at btinternet.com
Sat Aug 2 10:07:11 CEST 2008
"Fred @ Mac" <fredp101 at mac.com> wrote
> for f in os.listdir(watch_dir):
> tree = ET.parse(f)
> for shot in tree.findall('Shot'):
> ..do stuff..
>
> But my script fails if, for example, a directory also exists in
> "watch_dir"
Take a look at os.walk which allows recursive traversal of
a directory structure.
There is a short discussion in the OS topic on my web tutor.
HTH,
--
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld
More information about the Tutor
mailing list