pulling a file with today's date

Discussion in 'Ruby' started by Peter Bailey, Oct 15, 2007.

  1. Peter Bailey

    Peter Bailey Guest

    Hi,
    Can someone please help me to parse a file by its date so that, when I
    ftp to a site, I only pull those files that are dated with today's date,
    nothing else? I'm OK with pulling all files over, looking at them on my
    side of the fence, and then just discarding those files that aren't
    timestamped with today's date.

    Thanks,
    Peter
    --
    Posted via http://www.ruby-forum.com/.
     
    Peter Bailey, Oct 15, 2007
    #1
    1. Advertising

  2. Peter Bailey

    Phrogz Guest

    On Oct 15, 1:35 pm, Peter Bailey <> wrote:
    > Can someone please help me to parse a file by its date so that, when I
    > ftp to a site, I only pull those files that are dated with today's date,
    > nothing else? I'm OK with pulling all files over, looking at them on my
    > side of the fence, and then just discarding those files that aren't
    > timestamped with today's date.


    I believe this will depend on the FTP server running on the host,
    since different FTP servers will produce different results format.

    Care to post a small example of the result you see from the FTP server
    when you issue a 'dir' command?
     
    Phrogz, Oct 15, 2007
    #2
    1. Advertising

  3. Peter Bailey

    Ben Giddings Guest

    On Monday 15 October 2007, Peter Bailey wrote:
    > Hi,
    > Can someone please help me to parse a file by its date so that, when I
    > ftp to a site, I only pull those files that are dated with today's

    date,
    > nothing else? I'm OK with pulling all files over, looking at them on

    my
    > side of the fence, and then just discarding those files that aren't
    > timestamped with today's date.


    When you say "parse a file", do you mean parse the contents of the file,
    or simply select a specific file? I think you're talking about
    choosing a file based on the filename matching a date, but I'm not
    sure.

    The answer really depends on the format of the date. If it's a nice
    iso8601 format date string (i.e. YYYY-MM-DD) it's a little easier than
    other formats, but none of them is really hard. Basically all you have
    to do is create a regular expression object that will match the pattern
    you're looking for. You create the regexp based off a date string that
    comes from today's date

    For example, if the file is 2007-10-15-secretdata.zip:

    First create a string with the current date formatted however the date
    in the filename is formatted:
    date_str = Time.new.strftime("%Y-%m-%d")

    Next create a regular expression based on that string:
    file_match_regex = Regexp.new("^" + date_str + "-secretdata.zip$")

    Finally match the filenames against that regular expression:
    irb(main):008:0> file_match_regex.match("2007-10-15-secretdata.zip")
    => #<MatchData:0xb7a3be04>
    irb(main):009:0> file_match_regex.match("2007-10-16-secretdata.zip")
    => nil

    If you want to do this on the remote files, you'll probably want to use
    Ruby's FTP libraries. If you want to do it after you transfer the
    files over, you can transfer the file and then check them based on
    whatever matches the regexp.

    Ben
     
    Ben Giddings, Oct 15, 2007
    #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. TB
    Replies:
    0
    Views:
    463
  2. Peter Grison

    Date, date date date....

    Peter Grison, May 28, 2004, in forum: Java
    Replies:
    10
    Views:
    3,301
    Michael Borgwardt
    May 30, 2004
  3. Jim in Arizona
    Replies:
    3
    Views:
    575
    Jim in Arizona
    Sep 5, 2006
  4. Vinnie Davidson

    ASP Date: get records with date = today (SQL Server)

    Vinnie Davidson, Aug 13, 2005, in forum: ASP General
    Replies:
    6
    Views:
    335
    Aaron Bertrand [SQL Server MVP]
    Aug 15, 2005
  5. joeyej
    Replies:
    7
    Views:
    157
    Randy Webb
    Apr 6, 2006
Loading...

Share This Page