fnmatch on filename (without specific extension)

K

kepioo

Hi,


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


Any idea, help?

Regards,
 
P

Peter Hansen

kepioo said:
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
 
K

kepioo

i agree with you, it is better to find by ourself.

i managed to do it, but i left the code at work. i used the re module ,
using a re.match("Results Log") and a re.search(date) with a function
to find the date og the day with the appropriate format.

Is it ok to use re for file names? or fnmatch is more efficient?

thanks anyway!

Nassim
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top