划分来自FSO的文件

时间:2014-07-30 05:00:26

标签: javascript fso

我这里有一个代码,它会为我提供保存在文件夹中的文件数量:

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

如果我在&var; var文件中放入更多元素,那么“守则”就是完美的。我将获得所需的所有div元素,但我已将它们手动放入' var文件'中。如何将所有收集的文件名放入' var文件'自动?有什么想法吗?

1 个答案:

答案 0 :(得分:0)

我认为您可以尝试这样的方法来使用收集的文件名填充数组:

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