Forum: Ruby Search for string in folder names

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
3083ca8f0496edaac2fa10c20630d0bc?d=identicon&s=25 Newb Newb (newb)
on 2009-01-29 05:00
Hi ...
I will be getting some string through params[:first_name].and i want to
get that
what are all the folders names contain that string.
For example
I have folders names  like below
each one is folder name

Now if i enter "joy" into that first name text box
i want to get all the folders which has joy in the folder names
for the above example i will have to get the below results for the
folder search because it contains joy in the folder name

pls help me up how can i implemend this.
Thanks in advance

5772c599ccab3081e0fffb1d54f3b6de?d=identicon&s=25 Andrew Timberlake (andrewtimberlake)
on 2009-01-29 05:06
(Received via mailing list)
On Thu, Jan 29, 2009 at 5:58 AM, Newb Newb

> pls help me up how can i implemend this.
> Thanks in advance
> Cheers
> --
> Posted via

Think carefully about the security of working with input directly from
input on the file system.

Andrew Timberlake

"I have never let my schooling interfere with my education" - Mark Twain
3d61a8dbbd64d0feed8698689cf15276?d=identicon&s=25 Jayce Meade (Guest)
on 2009-01-29 05:10
(Received via mailing list)
I am no expert in this, just my two cents,but I would do the following:

def getNames(param, directory = Dir.getwd)
    foldernames, matches = Dir.entries(directory), []
    foldernames.each { |fn|
        if fn.include?(param) then matches.push(fn) end
    puts matches.join("\n")

I'm not an expert as I've said, but for just creating a list of folders
match your parameters, such as joy, I think that would retrieve an array
strings for filenames that include the string passed for 'param' in the
directory passed to 'directory' or the current directory if one is not

Doesn't solve your text box part, but I'd try something along the lines
what I put above to retrieve the filenames. Hope that helps you. :)

  - Jayce
From: "Newb Newb" <>
Sent: Wednesday, January 28, 2009 7:58 PM
Newsgroups: comp.lang.ruby
To: "ruby-talk ML" <>
Subject: Search for string in folder names
This topic is locked and can not be replied to.