Search for string in folder names

N

Newb Newb

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


(e-mail address removed)[email protected]
(e-mail address removed)[email protected]
(e-mail address removed)[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

(e-mail address removed)[email protected]
(e-mail address removed)[email protected]


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


Cheers
 
A

Andrew Timberlake

[Note: parts of this message were removed to make it a legal post.]

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


(e-mail address removed)[email protected]
(e-mail address removed)[email protected]
(e-mail address removed)[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

(e-mail address removed)[email protected]
(e-mail address removed)[email protected]


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


Cheers
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 Timberlake
http://ramblingsonrails.com
http://www.linkedin.com/in/andrewtimberlake

"I have never let my schooling interfere with my education" - Mark Twain
 
J

Jayce Meade

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
 

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
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top