[英]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.