pulling a file with today's date

P

Peter Bailey

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
 
P

Phrogz

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?
 
B

Ben Giddings

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
 

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,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top