[Tutor] search the folder for the 2 files and extract out only theversion numbers 1.0 and 2.0.

Alan Gauld alan.gauld at btinternet.com
Tue Nov 17 09:10:41 CET 2009

"MARCUS NG" <markersng at gmail.com> wrote

> what is the best way to look into the allFiles directory, and only search
> the folder for the 2 files myTest1.0.zip and myTest2.0.zip to extract out
> only the version numbers 1.0 and 2.0.

You probably want to use the glob.glob() function to search using
a pattern like myTest*.zip.

Then you can iterate over the list of names returned and examoine the
version number using normal sring functions (or reguar expressions)

> so I did think of listing the file names in an array only to realise that 
> I
> wouldn't know which index to query if this script is going to be 
> automated.

In Python you hardly ever need to query the index to extract items
from a list, instead you use a for loop to look at each item in turn.

for filename in glob.glob(pattern):
     version = extractVersion(filename)
    # etc...


Alan Gauld
Author of the Learn to Program web site

More information about the Tutor mailing list