Created
January 19, 2016 15:47
-
-
Save lgriffin/9ede2e9f7b9be1fb8936 to your computer and use it in GitHub Desktop.
Directory watcher and Total Size reported
This file contains 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
var chokidar = require('chokidar'); | |
var dir = '.'; | |
var du = require('du'); | |
var watcher = chokidar.watch(dir, {ignored: /[\/\\]\./}); | |
function getSize() | |
{ | |
du(dir, function (err, size) { | |
console.log('The current size of ' + dir + ' is:', size, 'bytes'); | |
}); | |
} | |
watcher | |
.on('change', function(path) { | |
console.log('File', path, 'has been changed'); | |
getSize(); | |
}) | |
.on('unlink', function(path) { | |
console.log('File', path, 'has been removed'); | |
getSize(); | |
}) | |
.on('add', function(path) { | |
//console.log('File', path, 'has been added'); | |
// Deliberately leaving this commented out to avoid wall of initial spam!! | |
}) | |
.on('unlinkDir', function(path) { | |
console.log('Directory', path, 'has been removed'); | |
getSize(); | |
}); |
watcher.on('all', function(event, path) {
console.log(event, path);
});
Is also valid for a catch all, the gist above gives more fine grained control and can minimise noise.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Currently turning off the initial add logging as it creates a spam wave off the bat!