Over a million developers have joined DZone.

Find All Subdirectories Of A Given Path At A Particular Depth

·

def subdirectories_of(path, options = {}) depth = options[:at_depth_of] || 1 Dir[File.join(path, * ["*"] * depth + [""])] end >> subdirectories_of("/var") => ["/var/agentx/", "/var/amavis/", "/var/at/", "/var/audit/", "/var/backups/", "/var/db/", "/var/empty/", "/var/folders/", ...] >> subdirectories_of("/var", :at_depth_of => 2) => ["/var/amavis/db/", "/var/amavis/tmp/", "/var/at/jobs/", "/var/at/spool/", "/var/at/tabs/", "/var/at/tmp/", 
Topics:

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}