nsIDirectoryServiceProvider 编辑

xpcom/io/nsIDirectoryService.idlScriptable This interface is used by the Directory Service to get file locations. Inherits from: nsISupports Last changed in Gecko 1.7

nsIDirectoryServiceProvider.

Method overview

nsIFile getFile(in string prop, out PRBool persistent);

Methods

getFile()

The Directory Service calls this method when it gets the first request for a prop or on every request if the prop is not persistent.

nsIFile getFile(
  in string prop,
  out PRBool persistent
);
Parameters
prop
The symbolic name of the file.
persistent
true if the returned file will be cached by Directory Service. Subsequent requests for this prop will bypass the provider and use the cache. false if the provider will be asked for this prop each time it is requested.
Return value

The nsIFile represented by the property.

Example

This code creates a global, read-only string called currDir with the value of the current working directory.

 __defineGetter__("currDir",
                  function getCurrDir() {
                    return Components.classes["@mozilla.org/file/directory_service;1"]
                                     .getService(Components.interfaces.nsIDirectoryServiceProvider)
                                     .getFile("CurWorkD",{}).path;
                   });

Test it with to see the magic happen.

 alert(currDir);

See also

Additionally, see section 16.5.2 of the Rapid Application Development with Mozilla book for instructions on how to get the current working directory and the process binary directory, among other things.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:90 次

字数:3245

最后编辑:7年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文