Skip to content

Instantly share code, notes, and snippets.

View skw's full-sized avatar

Shaun Wong skw

  • GitHub Staff
  • Calgary, AB
View GitHub Profile
@skw
skw / tree.coffee
Last active December 15, 2015 06:39
node.js coffeescript function that returns json tree representation of directory structure
fs = require 'fs' # node file system module
path = require 'path' # node path module
# returns json tree representation of directory structure
tree = (root) ->
# clean trailing '/'
root = root.replace /\/+$/ , ""
# extract tree ring if root exists
if fs.existsSync root
ring = fs.lstatSync root