Ruby script to take single regular expression and search directory

I am brand new to Ruby. Just started learning it yesterday and I am trying to write a ruby script. It takes a single regular expression as a command line argument and searches the current directory and all its subdirectories for:
files with names that match the given regular expression & files that have content that matches the given regular expression. At least, that is what i want it to do but it isn't yet. Can i get some help please?

here is all i have so far:
puts "Enter path"
#str = gets.chomp
#puts Dir.entries(str)

#eval #like running script to read another script
#ARGV[0] #output first command line arg 
#puts ARGV[1]
#a = (/in/ =~ 'filename')
#a = (/ =~ '')
a = ARGV[0]
b = ARGV[1]
c = (a =~ b)
#concat some text before c
puts c

Open in new window

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

I suggest starting to search for the Files in the current directory. Check
Dir.glob for trying to match the files.

Then filter out directories change into the directory and run the in it also.

For directory handling you may like to have a look at:

The idea is simple.
You write  method which takes one parameter (a directory)
you filter out all the elements which are directories also and
call the above method again
If there is no more directory you run the
Dir.glob method to filter for the file_names
you append them e.g to an Array
on working out of the recursion you simply append
the Elements found by Dir.glob to the Array

It's easier to program as to describe ;-)

Here is an example on how to use Glob

files = Dir.glob("*.txt")"output", "w") do |out|
    files.each do | file |
       out.print("#{file} ")

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.