I've here an code which gives me the amount of the files, saved in an Folder:
//get file amount in folder
var fileAmount = new ActiveXObject("Scripting.FileSystemObject");
var folderObj = fileAmount.GetFolder("C:\\cnc\\USER"); //pfad, dann in benuzername/dokumente
// create enumerator type of collection of files in folder
var filesCollection = new Enumerator(folderObj.Files);
var fileObj;
for (filesCollection.moveFirst(); !filesCollection.atEnd(); filesCollection.moveNext()) {
fileObj = filesCollection.item();
projName = fileObj.Name;
alert(projName) ; // at the Moment msg. with all file names...
}
And I want to Import them here in "var files":
var files = [
{'name': projName + ',', 'date': ProjDate + ' '} //date is also there but not in the code
],
insertDiv = function(openerWrapper, file){
// create element
var div = document.createElement('div'),
content = "",
_key;
for(_key in file){
if(file.hasOwnProperty(_key)){
content += " " + file[_key];
}
}
// this is content
div.innerHTML = content;
// CSS class
div.className += " metroFileBoxAuto";
openerWrapper.appendChild(div);
};
The Code is working perfect, if I put more elements in 'var files' I'll get all div elements I needed, but I've to put them manually in the 'var files'. How I can put all the collected filenames in 'var files' automatically? Any idea?
I think you can try something like this to populate the array with collected filenames:
//get file amount in folder
var fileAmount = new ActiveXObject("Scripting.FileSystemObject");
var folderObj = fileAmount.GetFolder("C:\\cnc\\USER"); //pfad, dann in benuzername/dokumente
// create enumerator type of collection of files in folder
var filesCollection = new Enumerator(folderObj.Files);
var fileObj, files[], projName;
for (filesCollection.moveFirst(); !filesCollection.atEnd(); filesCollection.moveNext()) {
fileObj = filesCollection.item();
projName = fileObj.Name;
alert(projName) ; // at the Moment msg. with all file names...
files.push({'name': projName + ' ,', 'date': 'some_date' + ' '});
}