# Pulling a file with today's date

**URL:** <https://www.ruby-forum.com/t/pulling-a-file-with-todays-date/117310>\
**Category:** Ruby\
**Created:** [October 15, 2007, 9:35pm UTC](https://www.ruby-forum.com/t/pulling-a-file-with-todays-date/117310 "2007-10-15T21:35:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bodikp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e79b87/32.png) [@bodikp](https://www.ruby-forum.com/u/bodikp)\
**Post date:** [October 15, 2007, 9:35pm UTC](https://www.ruby-forum.com/t/pulling-a-file-with-todays-date/117310/1 "2007-10-15T21:35:49Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![bodikp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e79b87/32.png) [@bodikp](https://www.ruby-forum.com/u/bodikp)\
**Post date:** [October 15, 2007, 10:50pm UTC](https://www.ruby-forum.com/t/pulling-a-file-with-todays-date/117310/2 "2007-10-15T22:50:21Z")

</div>

On Oct 15, 1:35 pm, Peter B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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?

---

<div class="post-metadata">

**Author:** ![bodikp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e79b87/32.png) [@bodikp](https://www.ruby-forum.com/u/bodikp)\
**Post date:** [October 15, 2007, 11:41pm UTC](https://www.ruby-forum.com/t/pulling-a-file-with-todays-date/117310/3 "2007-10-15T23:41:55Z")

</div>

On Monday 15 October 2007, Peter B. 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
