Search for string in folder names

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

[email protected][email protected]
[email protected][email protected]
[email protected][email protected]

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

    [email protected][email protected]
    [email protected][email protected]

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

Cheers

On Thu, Jan 29, 2009 at 5:58 AM, Newb N.
[email protected]wrote:

[email protected][email protected]

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

Cheers

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

Dir.glob(“/path/to/base/dir/#{search_string}”)

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


Andrew T.
http://ramblingsonrails.com
http://www.linkedin.com/in/andrewtimberlake

“I have never let my schooling interfere with my education” - Mark Twain

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”)
end

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

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

  • Jayce

From: “Newb N.” [email protected]
Sent: Wednesday, January 28, 2009 7:58 PM
Newsgroups: comp.lang.ruby
To: “ruby-talk ML” [email protected]
Subject: Search for string in folder names