Forum: Ruby Search for string in folder names

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community 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


    1.kannan@angleritech.com~Vs~joy@angleritech.com
    2.martin@angleritech.com~Vs~joy@angleritech.com
    3.martin@angleritech.com~Vs~priya@angleritech.com


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

        kannan@angleritech.com~Vs~joy@angleritech.com
        martin@angleritech.com~Vs~joy@angleritech.com


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


Cheers
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
<revathy.p@angleritech.com>wrote:

>    2.martin@angleritech.com~Vs~joy@angleritech.com
>
>
> 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 Timberlake
http://ramblingsonrails.com
http://www.linkedin.com/in/andrewtimberlake

"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")
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 Newb" <revathy.p@angleritech.com>
Sent: Wednesday, January 28, 2009 7:58 PM
Newsgroups: comp.lang.ruby
To: "ruby-talk ML" <ruby-talk@ruby-lang.org>
Subject: Search for string in folder names
This topic is locked and can not be replied to.