When I do console.log(stats)
in a fs.stats
function for a file, it gives me something like this:
{ dev: 16777223,
mode: 33188,
nlink: 1,
uid: 501,
gid: 20,
rdev: 0,
blksize: 4096,
ino: 49868100,
size: 5617,
blocks: 16,
atime: Mon Jan 05 2015 18:18:10 GMT-0700 (MST),
mtime: Thu Sep 25 2014 21:21:28 GMT-0600 (MDT),
ctime: Thu Sep 25 2014 21:21:28 GMT-0600 (MDT),
birthtime: Thu Sep 25 2014 21:21:28 GMT-0600 (MDT),
name: 'README.md',
type: 'file' }
Here's the code, I'm using the walk node plugin. The function runs every time it finds a file.
walker.on('files', function(path, stats, next){
console.log(stats.name);
next();
});
But when I do console.log(stats.name)
, it says that it is undefined. Does anyone know what I'm doing wrong? Am I using the wrong property somehow?
You are using walker on files
not walker on file
. So stats might contain an array of files not only one. Try console.log(stats)
to see the stats argument structure for files
.
Or maybe try walker.on('file', function(path, stats, next){});