Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7935779
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T22:01:28+00:00 2026-06-03T22:01:28+00:00

I need to find all strings, which contain <some_word> . There is MAIN directory,

  • 0

I need to find all strings, which contain <some_word>. There is MAIN directory, where we have to search and there can be files and other directroies (with files). It must enter one directory – check all files there for <some_word>, return to main directory – enter another directroy – check all files there, return to main directory… and so on and so for. I have no problems to make this, when there are only files in main directory… but don’t know how to make it with directories… please help me.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T22:01:30+00:00Added an answer on June 3, 2026 at 10:01 pm

    To process all files in a directory:

    Dir['**/*'].each do |filepath|
      # filepath is a string path to the file or directory
      # relative from the working directory of the script
    end
    

    For more information, see the documentation for Dir.[] or Dir.glob.

    Thus, if you already have find_text_in_file( some_word, filepath ) you can do:

    Dir['**/*'].select{|f| File.file?(f) }.each do |filepath|
      find_text_in_file( some_word, filepath )
    end
    

    Note that the above will search the files in a depth-first traversal. If you want to search in a breadth-first manner you can instead use this:

    files = Dir['**/*'].select{ |f| File.file?(f) }
    files.sort_by{ |f| f.split(File::SEPARATOR).length }.each do |filepath|
      find_text_in_file( some_word, filepath )
    end
    

    Alternatively, if you already have find_word_in_directory( some_word, dirpath ) then you can do:

    Dir['**/*'].select{ |f| File.directory?(f) }.each do |dirpath|
      find_word_in_directory( some_word, dirpath )
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to find all image files from directory (gif, png, jpg, jpeg). find
I need to find all instances of strings within an xml node. To be
I need to find all patrons that have at least 1 circulation record. Here's
I have a std::vector with the element as pair and need to find all
I have a many_to_many relationship between ImageShells and Users. I need to find all
I need to find all descendants of a category using HierarchyID for SQL Server
I need to find all monomials in the form A X that when evaluated
Let's say i need to find all .bar elements inside an element that's assigned
I am currently working in an application where I need to find all occurrences
I need to be able to find all grids for a given form. This

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.