无法使用ActiveXObject('Scripting.FileSystemObject')和JS获取子文件夹的名称

时间:2018-05-25 18:38:46

标签: javascript activex hta filesystemobject

我正在尝试使用我的HTA文件中的JavaScript和Windows“ActiveXObject('Scripting.FileSystemObject')获取文件夹内的子文件夹名称:

var fso = new ActiveXObject('Scripting.FileSystemObject');
var subfolders = fso.GetFolder('D:\path\to\myfolder\').SubFolders;
for(var i = 0; i < subfolders.length; i++) {
    alert(subfolders[i].Name);
}

OR

var fso = new ActiveXObject('Scripting.FileSystemObject');
for(var subfolder in fso.GetFolder('D:\path\to\myfolder\').SubFolders) {
    alert(subfolder.Name);
}

但在这两种情况下我什么都没得到。怎么了?

1 个答案:

答案 0 :(得分:1)

好的,我找到了这个解决方案:

var fso = new ActiveXObject('Scripting.FileSystemObject');
var e = new Enumerator(fso.GetFolder('D:\path\to\myfolder\').SubFolders);
for(;!e.atEnd();e.moveNext()) {
    alert(e.item().Name);
}