Thursday, 15 July 2010

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



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

this works:

var promise = new future(), dirs = [], stat; fs.readdir(root + p, function(error, files){ _.each(files, function(file) { //stat = fs.statsync(file); //if ( stat.isdirectory() ) { dirs.push(file); //} }); promise.return(dirs); });

this not:

var promise = new future(), dirs = [], stat; fs.readdir(root + p, function(error, files){ _.each(files, function(file) { stat = fs.statsync(file); if ( stat.isdirectory() ) { dirs.push(file); } }); promise.return(dirs); });

resulting in "error: enoent, no such file or directory 'fonts'"

fonts first directory in tree, , exist.

i've gotta missing silly. i'm trying homecoming folder/directory names only.

while i'm @ it, know how homecoming levels of directories?

for example, result be:

[ "fonts", "fonts/font-awesome", "images", "images/somepath", "images/somepath/anotherpath" ]

that next goal, after figuring out i'm doing wrong.

i appreciate help!

readdir give names of entries in folder, not whole path. 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); });

node.js npm fs

No comments:

Post a Comment