simple get file by filename

E

eggie5

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

Gregory Brown

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.*"]
 
E

eggie5

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

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.*"]

Confirmed.
 

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
474,264
Messages
2,571,323
Members
48,005
Latest member
ChasityFan

Latest Threads

Top