Created
July 5, 2013 06:32
-
-
Save capaj/5932405 to your computer and use it in GitHub Desktop.
just listing files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var listFilesIn = function (name) { | |
var def = when.defer(); | |
fs.readdir(basePath+name, function (err, files) { | |
if (err) { | |
def.reject(err); | |
} | |
var onlyfiles = []; | |
function checkIsFile(file, callback) { | |
// console.log("will check file: " + file); | |
fs.lstat(basePath + name + '/' + file, function(err, stats) { | |
if (!err && !stats.isDirectory()) { //condition for identifying folders | |
onlyfiles.push(file); | |
// console.log('Pushed file: '+file); | |
callback(); | |
} else { | |
if(err){ | |
console.warn("Error occured: " + err ); | |
} | |
} | |
}); | |
} | |
if (files) { | |
async.each(files, checkIsFile, function(err){ | |
if (err) { | |
def.reject(err); | |
} | |
def.resolve(onlyfiles); | |
}); | |
} else { | |
def.reject('No files found'); | |
} | |
}); | |
return def.promise; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment