我在这里,一个代码,它给了我文件量,保存在文件夹中:

//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...
}  
.

,我想在这里在“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);
};
.

代码是完美的,如果我在'var文件'中放入更多元素,我会得到我需要的所有div元素,但我要在'var文件'中手动将它们放在上面。我如何将所有收集的文件名自动将所有收集的文件名放在'var文件'中?任何想法?

有帮助吗?

解决方案

我想你可以尝试这样的东西来填充收集的文件名:

//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' + '  '});
}
.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top