Search code examples
rubydirectorydirectory-listing

Getting a list of folders in a directory


How do I get a list of the folders that exist in a certain directory with ruby?

Dir.entries() looks close but I don't know how to limit to folders only.


Solution

  • Jordan is close, but Dir.entries doesn't return the full path that File.directory? expects. Try this:

     Dir.entries('/your_dir').select {|entry| File.directory? File.join('/your_dir',entry) and !(entry =='.' || entry == '..') }