簡體   English   中英

熱到列出具有XPCOM的文件夾中的所有文件

[英]Hot to list all files from a folder with XPCOM

我想使用XPCOM和iMacros列出文件夾中的所有圖像。 貝婁是我使用的代碼,但是我收到了錯誤。

ReferenceError: file is not defined, line 319 (Error code: -991)

這是我正在使用的代碼示例。

   var imageurl =  "s:\\images\\";

imageurl = CheckFolder(imageurl);

alert(imageurl);

function CheckFolder(path) {

            alert(path)
            file.initWithPath(path);
            var children = file.directoryEntries;
            var child;
            var list = [];
            while (children.hasMoreElements()) {
                child = children.getNext().QueryInterface(Components.interfaces.nsILocalFile);
                list.push(child.leafName + (child.isDirectory() ? ' [DIR]' : ''));
            }
            alert(list.join('\n'));
        }

這是我通過上面的鏈接制作的解決方案。 你是對的目標。

//找到文件夾中的所有文件

function CheckFolder(filePath) {



    var nsFile = Components.Constructor("@mozilla.org/file/local;1", "nsIFile", "initWithPath");

    var file = new nsFile(filePath);

    //file.initWithPath(filePath);
    var children = file.directoryEntries;
    var child;
    var list = [];
    while (children.hasMoreElements()) {
        child = children.getNext().QueryInterface(Components.interfaces.nsILocalFile);
        list.push(child.leafName + (child.isDirectory() ? ' [DIR]' : ''));
    }
    alert(list.join('\n'));

    return list;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM