fs.readdir('../../angular-phonecat', function(err, fileList){
if (err) throw err;
console.log(fileList);
fileList.forEach(function(f) {
fs.stat(f, function(){
console.log(arguments);
})
})
})
报错信息
[ '.DS_Store',
'.bowerrc',
'.git',
'.gitignore',
'.jshintrc',
'.travis.yml',
'LICENSE',
'README.md',
'app',
'bower.json',
'karma-26468570',
'karma-41043336',
'node_modules',
'package.json',
'scripts',
'test' ]
{ '0': { [Error: ENOENT: no such file or directory, stat '.DS_Store'] errno: -2, code: 'ENOENT', syscall: 'stat', path: '.DS_Store' } }
{ '0': { [Error: ENOENT: no such file or directory, stat '.bowerrc'] errno: -2, code: 'ENOENT', syscall: 'stat', path: '.bowerrc' } }
{ '0': { [Error: ENOENT: no such file or directory, stat '.git'] errno: -2, code: 'ENOENT', syscall: 'stat', path: '.git' } }
{ '0': { [Error: ENOENT: no such file or directory, stat '.jshintrc'] errno: -2, code: 'ENOENT', syscall: 'stat', path: '.jshintrc' } }
{ '0':
{ [Error: ENOENT: no such file or directory, stat '.travis.yml']
errno: -2,
code: 'ENOENT',
syscall: 'stat',
path: '.travis.yml' } }
{ '0': { [Error: ENOENT: no such file or directory, stat '.gitignore'] errno: -2, code: 'ENOENT', syscall: 'stat', path: '.gitignore' } }
{ '0': { [Error: ENOENT: no such file or directory, stat 'LICENSE'] errno: -2, code: 'ENOENT', syscall: 'stat', path: 'LICENSE' } }
{ '0': { [Error: ENOENT: no such file or directory, stat 'README.md'] errno: -2, code: 'ENOENT', syscall: 'stat', path: 'README.md' } }
{ '0': { [Error: ENOENT: no such file or directory, stat 'app'] errno: -2, code: 'ENOENT', syscall: 'stat', path: 'app' } }
{ '0': { [Error: ENOENT: no such file or directory, stat 'bower.json'] errno: -2, code: 'ENOENT', syscall: 'stat', path: 'bower.json' } }
{ '0':
{ [Error: ENOENT: no such file or directory, stat 'karma-26468570']
errno: -2,
code: 'ENOENT',
syscall: 'stat',
path: 'karma-26468570' } }
{ '0':
{ [Error: ENOENT: no such file or directory, stat 'karma-41043336']
errno: -2,
code: 'ENOENT',
syscall: 'stat',
path: 'karma-41043336' } }
{ '0':
{ [Error: ENOENT: no such file or directory, stat 'node_modules']
errno: -2,
code: 'ENOENT',
syscall: 'stat',
path: 'node_modules' } }
{ '0':
{ [Error: ENOENT: no such file or directory, stat 'package.json']
errno: -2,
code: 'ENOENT',
syscall: 'stat',
path: 'package.json' } }
{ '0': { [Error: ENOENT: no such file or directory, stat 'scripts'] errno: -2, code: 'ENOENT', syscall: 'stat', path: 'scripts' } }
{ '0': { [Error: ENOENT: no such file or directory, stat 'test'] errno: -2, code: 'ENOENT', syscall: 'stat', path: 'test' } }
Usually use absolute paths
System variables
__dirname
is the path to the js file where you start the project. You can splice it into various pathssuch as
What happened to this message? Wasn't it just you who printed it out in
console.log(arguments);
? If your question is why all errors are printed instead of the realmetadata
of the file, then there is something wrong with your code. Change it to this: