Divide los archivos obtienen de la FSO
-
21-12-2019 - |
Pregunta
He aquí un código que me da la cantidad de los archivos, guardados en una carpeta:
//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...
}
y quiero importarlos aquí en "archivos VAR":
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);
};
El código está funcionando perfecto, si pongo más elementos en 'Var Archivos', obtendré todos los elementos DIV que necesitaba, pero tengo que ponerlos manualmente en los 'archivos VAR'.¿Cómo puedo poner todos los nombres de archivo recopilados en 'Var Archivos' automáticamente?¿Alguna idea?
Solución
Creo que puedes probar algo como esto para rellenar la matriz con nombres de archivo recolectados:
//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' + ' '});
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow