Simple get file by filename

Consider this:

I have a list of files that I get by calling:

Dir.entries("/")

I just want to search this list and match the file name that matches
1_1.* ( i.e. the filename without the extension)

So, for example, If the pattern to match against the list was
"jpg_image." it should return the filename "jpg_image.jpg" (assuming
the file exists).

What's the most succinct way to do this in ruby?

Dir["/jpg_image.*"]

···

On 9/5/07, eggie5 <eggie5@gmail.com> wrote:

Consider this:

I have a list of files that I get by calling:

Dir.entries("/")

I just want to search this list and match the file name that matches
1_1.* ( i.e. the filename without the extension)

So, for example, If the pattern to match against the list was
"jpg_image." it should return the filename "jpg_image.jpg" (assuming
the file exists).

What's the most succinct way to do this in ruby?

eggie5 wrote:

What's the most succinct way to do this in ruby?

Dir['1_1.*']
Dir['jpg_image.*']

ri Dir.glob

Regards,

···

--
Bil Kleb
http://fun3d.larc.nasa.gov

Confirmed.

···

On Sep 5, 2:00 pm, "Gregory Brown" <gregory.t.br...@gmail.com> wrote:

On 9/5/07, eggie5 <egg...@gmail.com> wrote:

> Consider this:

> I have a list of files that I get by calling:

> Dir.entries("/")

> I just want to search this list and match the file name that matches
> 1_1.* ( i.e. the filename without the extension)

> So, for example, If the pattern to match against the list was
> "jpg_image." it should return the filename "jpg_image.jpg" (assuming
> the file exists).

> What's the most succinct way to do this in ruby?

Dir["/jpg_image.*"]