Last active
February 28, 2018 19:27
-
-
Save korney4eg/462a3c51da1b8be4777fcbf0fcdefae4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def dirTree( path, pipes = '' ) | |
currentDirectory = Dir.new(path) | |
currentDirectory.sort.each.with_index do |file,index| | |
if file != '.' and file != '..' | |
if index == currentDirectory.sort.size - 1 | |
predictor = '└───' | |
nextChar = ' ' | |
else | |
predictor = '├───' | |
nextChar = '│' | |
end | |
output = "#{pipes}#{predictor}#{file}" | |
if File.ftype("#{path}/#{file}") == 'directory' | |
puts (output) | |
dirTree("#{path}/#{file}", "#{ pipes }#{nextChar}\t") | |
else | |
puts (output) | |
end | |
end | |
end | |
end | |
dirTree './testdata' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment