[Tutor] Can This Script Be Modified to Read Many Files?..

Alan Gauld alan.gauld at btinternet.com
Mon Jan 25 18:35:13 EST 2016


On 25/01/16 21:34, Sam Starfas via Tutor wrote:

> Can the below script be modified to scan/read all of the XML files in a directory

You could do it manually using

for file in glob.glob("*.xml"):

But you need to think about all the other possible file
endings too.

Or you could look at the fileinput module which takes a
different approach.

Finally if you need to process subdirectories too you
can use the os.walk() function

The Python docs describe how to use glob, fileinput
and os.walk.

HTH
-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Tutor mailing list