如何在 javascript 中获取子文件夹名称

how to get subfolder names in javascript

我在宏中使用 javascript 现在我需要从本地路径获取子文件夹的所有名称,将它们存储到一个数组中并将其传递给来自 javascript.using firefox 的宏 one bay one其中 ActiveX 不可用,那么获取子文件夹名称并将其传递给宏的最简单方法是什么?

也许,这种方式是最简单的:

/* indicate your folder */
var folder = "D:\Temp";

var dir = imns.Cc["@mozilla.org/file/local;1"].createInstance(imns.Ci.nsILocalFile);
dir.initWithPath(folder);
var subFolders = [];
var subFolderEnum = dir.directoryEntries;
while (subFolderEnum.hasMoreElements()) {
    var curSub = subFolderEnum.getNext().QueryInterface(imns.Ci.nsILocalFile);
    if (curSub.isDirectory()) {
        // subFolders.push(curSub.path);    // for the full path
        var subFolder = curSub.path;
        subFolder = subFolder.substr(subFolder.lastIndexOf("\") + 1);
        subFolders.push(subFolder);
    }

}

/* view the result */
alert(subFolders.join("\n"));