Skip to content

Instantly share code, notes, and snippets.

@korney4eg
Last active February 28, 2018 19:27
Show Gist options
  • Save korney4eg/462a3c51da1b8be4777fcbf0fcdefae4 to your computer and use it in GitHub Desktop.
Save korney4eg/462a3c51da1b8be4777fcbf0fcdefae4 to your computer and use it in GitHub Desktop.
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