Divida os arquivos obtidos do FSO
-
21-12-2019 - |
Pergunta
Tenho aqui um código que me dá a quantidade de arquivos salvos em uma pasta:
//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 quero importá-los aqui em "arquivos 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);
};
O código está funcionando perfeitamente, se eu colocar mais elementos em 'arquivos var' obterei todos os elementos div que precisava, mas tenho que colocá-los manualmente nos 'arquivos var'.Como posso colocar todos os nomes de arquivos coletados em 'arquivos var' automaticamente?Qualquer ideia?
Solução
Acho que você pode tentar algo assim para preencher o array com nomes de arquivos coletados:
//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 em: CC-BY-SA com atribuição
Não afiliado a StackOverflow