Lance Pollard Lance Pollard - 1 year ago 85
Ruby Question

One-liner to recursively list directories in Ruby?

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 Source
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).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download