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