Js - Getting A List Of Files And Directories From A Given Directory
I want to get a list of all files and directories in a specific path. lets say in 'C:\Dir1'
Solution 1:
you can use activex object as follow
functionShowFolderFileList(folderspec)
{
var fso, f, f1, fc, s;
fso = newActiveXObject("Scripting.FileSystemObject");
f = fso.GetFolder(folderspec);
fc = newEnumerator(f.files);
s = "";
for (; !fc.atEnd(); fc.moveNext())
{
s += fc.item();
s += "<br>";
}
return(s);
}
Solution 2:
Use findit
var finder = require('findit').find(__dirname);
var files = [];
finder.on('path', function (file, stat) {
files.push(file);
});
finder.on('end', function () {
console.log(files);
});
Post a Comment for "Js - Getting A List Of Files And Directories From A Given Directory"