Dividi i file ottengono da FSO
-
21-12-2019 - |
Domanda
Ho qui un codice che mi dà la quantità dei file, salvati in una cartella:
//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...
}
.
E voglio importarli qui 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);
};
.
Il codice funziona perfetto, se metto più elementi in "file VAR", riceverò tutti gli elementi div che avevo bisogno, ma devo metterli manualmente nei "file VAR".Come posso mettere automaticamente tutti i file raccolti in "file var"?Qualche idea?
Soluzione
Penso che tu possa provare qualcosa di simile per popolare l'array con i nomi di file raccolti:
//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' + ' '});
}
. Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow