index.js
function saveDirs(path, obj, cb) {
  var currDir = ''
  var root    = ''

  walk.walk(path, walkFn, function(err) {
    if (err) return cb(err)
    cb(null, obj)
  })

  function walkFn(baseDir, filename, stat, next) {
    if (!root) root = baseDir
    baseDir = stripLeadingSlash(baseDir.split(root)[1])

    if (!baseDir) return next()
    if (obj[baseDir]) return next()

    if (baseDir != currDir) currDir = baseDir

    if (stat.isDirectory()) {
      setObject(baseDir, obj, {})
      return next()
    }

    setObject(baseDir, obj, [])
    next()
  }
}
function saveDirs(path, obj, cb) {
  var currDir = ''
  var root    = ''

  walk.walk(path, walkFn, function(err) {
    if (err) return cb(err)
    cb(null, obj)
  })

  function walkFn(baseDir, filename, stat, next) {
    if (!root) root = baseDir
    baseDir = stripLeadingSlash(baseDir.split(root)[1])

    if (!baseDir) return next()
    if (obj[baseDir]) return next()

    if (baseDir != currDir) currDir = baseDir

    if (stat.isDirectory()) {
      setObject(baseDir, obj, {})
      return next()
    }

    setObject(baseDir, obj, [])
    next()
  }
}
function saveDirs ( path , obj , cb ) { var currDir = '' var root = '' walk . walk ( path , walkFn , function ( err ) { if ( err ) return cb ( err ) cb ( null , obj ) } ) function walkFn ( baseDir , filename , stat , next ) { if ( ! root ) root = baseDir baseDir = stripLeadingSlash ( baseDir . split ( root ) [ 1 ] ) if ( ! baseDir ) return next ( ) if ( obj [ baseDir ] ) return next ( ) if ( baseDir != currDir ) currDir = baseDir if ( stat . isDirectory ( ) ) { setObject ( baseDir , obj , { } ) return next ( ) } setObject ( baseDir , obj , [ ] ) next ( ) } }
Save directory structure. @param {String} path @param {Object} obj @param {Function} cb
Save directory structure .