Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > pulling a file with today's date

Reply
Thread Tools

pulling a file with today's date

 
 
Peter Bailey
Guest
Posts: n/a
 
      10-15-2007
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/.

 
Reply With Quote
 
 
 
 
Phrogz
Guest
Posts: n/a
 
      10-15-2007
On Oct 15, 1:35 pm, Peter Bailey <(E-Mail Removed)> 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?

 
Reply With Quote
 
 
 
 
Ben Giddings
Guest
Posts: n/a
 
      10-15-2007
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

 
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
Pulling from Access Query, Cannot Change Date/Time Formats Jim in Arizona ASP .Net 3 09-05-2006 10:00 PM
Pulling data based on date time returns error xhoster@gmail.com Perl Misc 5 08-17-2006 05:50 PM
Date, date date date.... Peter Grison Java 10 05-30-2004 01:20 PM
Given a date, how to find the beginning date and ending date of that week Matt ASP .Net 1 11-08-2003 09:14 PM
Given a date, how to find the beginning date and ending date of that week Matt C++ 2 11-08-2003 08:30 PM



Advertisments