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

前端 未结 1 969
谎友^
谎友^ 2021-01-14 02:25

This works:

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

    Fs.readdir(Root + p, function(error, files){
        _.each(files,          


        
相关标签:
1条回答
  • 2021-01-14 03:20

    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);
    });
    
    0 讨论(0)
提交回复
热议问题