Skip to content

Instantly share code, notes, and snippets.

@Raynos
Created November 30, 2011 15:27
Show Gist options
  • Save Raynos/1409470 to your computer and use it in GitHub Desktop.
Save Raynos/1409470 to your computer and use it in GitHub Desktop.
Recursive fs.watch
fs.readdir(srcPath, handleDirectoryRead.bind(null, srcPath));
function handleDirectoryRead(srcPath, err, files) {
files.forEach(handleFile.bind(null, srcPath));
}
function handleFile(srcPath, file) {
var uri = path.join(srcPath, file);
fs.stat(uri, handleStat.bind(null, uri));
}
function handleStat(uri, err, stat) {
if (stat.isDirectory()) {
fs.readdir(uri, handleDirectoryRead.bind(null, uri));
} else {
fs.watch(uri, build);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment