Using fs.readdir and fs.statSync returns ENOENT, no such file or directory error

天涯浪子 提交于 2019-12-01 08:43:14

readdir will give you the names of the entries in the folder, not the whole path. This will work:

stat = Fs.statSync(Root + p + "/" + file);

The whole code:

var promise = new Future(),
    dirs = [],
    stat,
    fullPath;


Fs.readdir(Root + p, function(error, files){
    _.each(files, function(file) {
        fullPath = Root + p + "/" + file;
        stat = Fs.statSync(fullPath);
        if ( stat.isDirectory() ) {
            dirs.push(fullPath);
        }
    });

    promise.return(dirs);
});
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!