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
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.
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
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.