-
-
Save synsa/ac783b65b958114c6917b7e07b4c202f 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
directoryWalker: (dir, callback, maxLevels, currentLevel, fromRoot) -> | |
maxLevels: if 'number' is typeof maxLevels then maxLevels else 0 | |
currentLevel: if 'number' is typeof currentLevel then currentLevel else 1 | |
fromRoot: if 'string' is typeof fromRoot then fromRoot else '' | |
fs.readdir dir, (error, files) -> | |
if error then puts error.message | |
else files.forEach (file) -> | |
fs.stat path.join(dir, file), (error, stats) -> | |
return puts error.message if error | |
if stats.isDirectory() | |
if 0 is maxLevels or maxLevels > currentLevel | |
directoryWalker path.join(dir, file), callback, | |
maxLevels, 1 + currentLevel, | |
fromRoot + file + '/' | |
callback.call stats, file, fromRoot, path.join(dir, file), stats |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment