MDN’s new design is in Beta! A sneak peek: https://blog.mozilla.org/opendesign/mdns-new-design-beta/

nsIDirectoryServiceProvider

本接口是目录服务用于得到文件位置的函数。
继承于: nsISupports 最后修改于Gecko 1.7

nsIDirectoryServiceProvider.

方法概览

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

方法

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.

示例

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

参见

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.

文档标签和贡献者

 此页面的贡献者: ziyunfei, iwo
 最后编辑者: ziyunfei,