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

  • SEARCH
  • Home
  • 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 6615393
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:27:22+00:00 2026-05-25T20:27:22+00:00

I am working on this ruby script where I have to recursively look inside

  • 0

I am working on this ruby script where I have to recursively look inside all the subdirectories starting at a particular directory. But for some reason FileTest.directory? only seems to recognise a directory if it is located in the same folder as the script

def files(start)
  dir = Dir.open (start)
  dir.each do |x|
    p "#{x}: #{FileTest.directory?(x)}"
    if FileTest.directory?(x) && x != '.' && x != '..'
      start = x
      files (start)
    end
  end
end
files '.'

Supposed my directory structure is as follows: In the current dir I have a file a.txt and two directories called ‘b’ and drct2. ‘b’ contains another directory ‘c’ and ‘drct’ contains another directory ‘dir3’. The code above when run from the current directory recognizes ‘b’ & ‘drct2’ as directories but not their sub directories. Can anyone think of a reason why FileTest.directory? is behaving this way?

  • 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-05-25T20:27:22+00:00Added an answer on May 25, 2026 at 8:27 pm

    You need to give a full path to the FileTest as it works relative to your current dir

    So if you have dira -> dirb -> filec you need to run:

    FileTest.directory?('dira/dirb')
    

    and not just

    FileTest.directory?('dirb')
    

    BTW I suggest you look into Dir.glob(‘**/*’) method – there is a good chance it does what you need to do out-of-the-box.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this working great, but I'd like a deeper understanding of what is
Okay so im working on this php image upload system but for some reason
I'm still working with this huge list of URLs, all the help I have
For some reason the script below is not working. This is the code I
Have been working in Ruby for a while, but usually in the context of
I have this working definition: IDENTIFIER [a-zA-Z][a-zA-Z0-9]* I don't want to keep repeating the
I have been working on this for the greater part of the day and
I have a ruby script repeatedly executing the following the INSERT statement using the
I have the jquery autocomplete example working on a test page, but can't seem
I am converting some php code into a Ruby script and I am attempting

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.