One-liner to recursively list directories in Ruby?

Lance Pollard picture Lance Pollard · Mar 3, 2010 · Viewed 64.1k times · Source

What is the fastest, most optimized, one-liner way to get an array of the directories (excluding files) in Ruby?

How about including files?

Answer

sepp2k picture sepp2k · Mar 3, 2010
Dir.glob("**/*/") # for directories
Dir.glob("**/*") # for all files

Instead of Dir.glob(foo) you can also write Dir[foo] (however Dir.glob can also take a block, in which case it will yield each path instead of creating an array).

Ruby Glob Docs