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

Timo timomlists at gmail.com
Tue Nov 17 08:00:21 CET 2009


I find regular expressions alwys hard to get, so here is my solution:

 >>> import glob
 >>> 
glob.glob('C:\\Users\\blueman\\Desktop\\allFiles\\MyTest[0-9].[0-9].zip')


Cheers,
Timo


MARCUS NG schreef:
> Hi all,
> I am really new to python and I am trying to create a script that 
> looks at file versions of a particular file
> I have 4 files in a folder. One called myTest1.0.zip, myTest2.0.zip, 
> test3.txt and test4.zip in a directory/folder called allFiles on my 
> desktop.
> so the file structure is as such
>
> C:\Users\blueman\Desktop\allFiles\myTest1.0.zip
> and
> C:\Users\blueman\Desktop\allFiles\myTest2.0.zip
>
> Aim:
> 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.
>
> what i have for my script so far is
> ############################
> import os
> #path of  scripts folder
> path="C:/Users/blueman/Desktop/allFiles/"
> dirList=os.listdir(path)
> for fname in dirList:
> print fname
> ############################
> 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.
>
> what is the best way to obtain the version numbers of the 2 files?
> thank you for your time.
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>   



More information about the Tutor mailing list