fnmatch on filename (without specific extension)

Peter Hansen peter at engcorp.com
Sun Apr 9 07:42:52 EDT 2006


kepioo wrote:
> I have some files in a directory :
> Results Log, 11;21AM, Apr 09 2006.txt
> Results Log, 11;21AM, Apr 08 2006.txt
> Results Log, 03;59AM, Apr 07 2006.txt
> otherfile1.txt
> otherfile2.txt
> 
> I'd like to copy all the Results Log file, whatever the hour but with a
> specific day. For instance, today ( 9th april), the script should copy
> the first file : Results Log, 11;21AM, Apr 09 2006.txt

So you need to be able to match on the relevant parts of the file name, 
which appear to be "Results Log" at the start of the name, and today's 
date formatted appropriately for the end, plus ".txt" as an extension. 
You seem to know about the existence of the fnmatch module, so what 
exactly are you having difficulty with?  Please post some code showing 
what you've been able to do so far.  (I could also just hand you an 
answer, but this isn't a difficult problem and you wouldn't learn as 
much as if you have to walk through it yourself.  Of course, inevitably 
somebody will post a complete answer anyway...)

-Peter




More information about the Python-list mailing list