function largest(dir, callback) {
var results = '';
fs.readdir(dir, function(err, list) {
if (err) {
return callback(null);
};
var i = 0;
(function next() {
var file = list[i++];
if (!file) return callback(null, results);
file = dir + '/' + file;
fs.stat(file, function(err, stat){
if(stat && stat.isDirectory()) {
largest(file, function(err, res){
next();
})
}else {
var size = fs.stat(results, function(err, stat) {
if(err)
return 0;
else
return stat.size;
})
if (stat.size > size){
results = file;
}
next();
};
});
})();
})
}
function callBack() {
if(arguments[1] === null)
console.log('Enter the path of illegal');
}
var arguments = process.argv.slice(2)[0];
largest(arguments, callBack());
求大神帮帮忙