Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > fnmatch on filename (without specific extension)

Reply
Thread Tools

fnmatch on filename (without specific extension)

 
 
kepioo
Guest
Posts: n/a
 
      04-09-2006
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,

 
Reply With Quote
 
 
 
 
Peter Hansen
Guest
Posts: n/a
 
      04-09-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

 
Reply With Quote
 
 
 
 
kepioo
Guest
Posts: n/a
 
      04-09-2006
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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
File.fnmatch? doesn't distinguish between .filename and ./filename ? Stefano Crocco Ruby 0 11-14-2008 10:48 AM
More Efficient fnmatch.fnmatch for multiple patterns? abcd Python 4 01-08-2007 07:19 PM
attribute error using fnmatch s99999999s2003@yahoo.com Python 2 06-05-2006 07:12 AM
fnmatch.h help kitty C++ 2 03-29-2006 04:28 AM
Regular Expression for fnmatch function Graeme Downes C Programming 1 01-14-2005 03:44 AM



Advertisments