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

Can't get names of subfolders using ActiveXObject('Scripting.FileSystemObject') and JS

我试图在我的 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);
}

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

但我在这两种情况下都一无所获。怎么了?

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

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