How to get a directory size of the current Total.js application?
- operations are supported in Total.js
+v2.4.0
- works in Linux or macOS
Create an operation
const Exec = require('child_process').exec;
NEWOPERATION('directorysize', function(error, value, callback) {
Exec('du -sk ' + (value === EMPTYOBJECT ? F.path.root() : value), function(err, response) {
err && error.push(err);
var size = null;
var match = response.trim().match(/^[\d\.\,]+/);
match && (size = match.toString().trim().parseInt2() * 1024);
callback(size);
});
});
Usage
You can execute the code below anywhere in your Total.js application:
OPERATION('directorysize', function(err, response) {
console.log(err, response.filesize());
});
// Or another directory e.g. "databases"
OPERATION('directorysize', F.path.databases(), function(err, response) {
console.log(err, response.filesize());
});
References