fnmatch on filename (without specific extension)

Discussion in 'Python' started by kepioo, Apr 9, 2006.

  1. kepioo

    kepioo Guest

    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,
     
    kepioo, Apr 9, 2006
    #1
    1. Advertising

  2. kepioo

    Peter Hansen Guest

    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
     
    Peter Hansen, Apr 9, 2006
    #2
    1. Advertising

  3. kepioo

    kepioo Guest

    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
     
    kepioo, Apr 9, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Joe
    Replies:
    7
    Views:
    2,488
    Matt Berther
    Feb 8, 2005
  2. Replies:
    7
    Views:
    4,421
    R. Rajesh Jeba Anbiah
    Feb 6, 2005
  3. abcd
    Replies:
    4
    Views:
    469
    Gabriel Genellina
    Jan 8, 2007
  4. Joe
    Replies:
    6
    Views:
    191
    teknohippy
    Feb 7, 2005
  5. Stefano Crocco
    Replies:
    0
    Views:
    158
    Stefano Crocco
    Nov 14, 2008
Loading...

Share This Page