Skip to content

Instantly share code, notes, and snippets.

@jankeesvw
Created August 10, 2012 07:08
Show Gist options
  • Save jankeesvw/3312107 to your computer and use it in GitHub Desktop.
Save jankeesvw/3312107 to your computer and use it in GitHub Desktop.
tree
#!/usr/bin/env ruby
def print_folder path, depth
supplement = ""
for i in 0..depth
supplement = supplement + " "
end
supplement = supplement + "+"
`cd #{path}; find . -type f -maxdepth 1`.each_line { | file |
file = file.match(/.\/(.*)/)[1]
puts "#{supplement} #{file}"
}
`cd #{path}; find . -type d -maxdepth 1`.each_line { | folder |
match = folder.match(/.\/(.*)/)
if match != nil
folder = match[1]
puts "#{supplement} #{folder}"
if depth > 3
puts "#{supplement} #{folder} [...]"
next
end
print_folder "#{path}/#{folder}", depth + 1
end
}
end
print_folder `pwd | tr -d '\n'`, 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment