Skip to content

Instantly share code, notes, and snippets.

@makevoid
Created September 25, 2010 03:50
Show Gist options
  • Select an option

  • Save makevoid/596445 to your computer and use it in GitHub Desktop.

Select an option

Save makevoid/596445 to your computer and use it in GitHub Desktop.
emulate tree (only dirs)
def entries(dir)
Dir.entries(dir) - ["..", "."]
end
def entries_map(directory, level=1, &block)
entries(directory).map do |dir|
if File.directory? "#{directory}/#{dir}"
puts "#{">"*level} #{dir}"
block.call "#{directory}/#{dir}"
end
end
end
entries_map(".", 1) do |dir|
entries_map(dir, 2) do |d|
entries_map(d, 3) do |dd|
# etc..
end
end
end
#puts `tree`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment