From: Kendall Gifford Date: 2013-02-15T09:48:28+09:00 Subject: Re: if file exists then move --f46d0402a9af666cc404d5b8a425 Content-Type: text/plain; charset=UTF-8 On Thu, Feb 14, 2013 at 4:59 PM, Sloan Ruby wrote: > I have been googling and am not sure how to approach this. I have a > file that I need to match. The date string in the filename varies so I > want to match any date. > > /path/to/file/hist_sar01-31-2013.tar > > What options do i have for matching the/any date or string. Is there a > method for matching? > > hist_sar*.tar > if Dir["/path/to/file/hist_sar*.tar"].empty? # code to run if no files matching pattern exist else # code to run otherwise end You could also make the pattern more specific: http://www.ruby-doc.org/core-1.9.3/Dir.html#method-c-glob Example: Dir["/path/to/file/hist_sar{0,1}[0-9]-[0-3][0-9]-[0-9][0-9][0-9][0-9].tar"] > > -- > Posted via http://www.ruby-forum.com/. > > -- Kendall Gifford zettabyte@gmail.com --f46d0402a9af666cc404d5b8a425 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
On Thu, Feb 14, 2013 at 4:59 PM, Sloan Ruby <lists@rub= y-forum.com> wrote:
I have been googling and = am not sure how to approach this. =C2=A0I have a
file that I need to match. =C2=A0The date string in the filename varies so = I
want to match any date.

/path/to/file/hist_sar01-31-2013.tar

What options do i have for matching the/any date or string. =C2=A0Is there = a
method for matching?

hist_sar*.tar

if Dir["/path/to/fil= e/hist_sar*.tar"].empty?
=C2=A0 # code to run if no file= s matching pattern exist
else
=C2=A0 # code to = run otherwise
end

You could also make the pattern more speci= fic: = http://www.ruby-doc.org/core-1.9.3/Dir.html#method-c-glob

Example: Dir["/path/to/file/hist_sar{0,1}[0-9]-[0-3][0-9]-[0-9][0= -9][0-9][0-9].tar"]

--
Posted via http://= www.ruby-forum.com/.




--
Kendall G= ifford
zettabyte@gmail.com
--f46d0402a9af666cc404d5b8a425--