Getting a list of folders in a directory

I’ve found this more useful and easy to use:

Dir.chdir('/destination_directory')
Dir.glob('*').select {|f| File.directory? f}

it gets all folders in the current directory, excluded . and ...

To recurse folders simply use ** in place of *.

The Dir.glob line can also be passed to Dir.chdir as a block:

Dir.chdir('/destination directory') do
  Dir.glob('*').select { |f| File.directory? f }
end

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)