nsIDirectoryServiceProvider

  • 版本网址缩略名: XPCOM_Interface_Reference/nsIDirectoryServiceProvider
  • 版本标题: nsIDirectoryServiceProvider
  • 版本 id: 377507
  • 创建于:
  • 创建者: iwo
  • 是否是当前版本?
  • 评论

修订内容

{{ IFSummary("xpcom/io/nsIDirectoryService.idl", "nsISupports", "Scriptable", "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 {{ Interface("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);

参见

  • nsDirectoryService
  • {{ Interface("nsIDirectoryService") }}
  • 其它目录服务关键字见[url=http://mxr.mozilla.org/mozilla-central/source/xpcom/io/nsDirectoryServiceDefs.h]nsDirectoryServiceDefs.h[/url]

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.

修订版来源

<p>{{ IFSummary("xpcom/io/nsIDirectoryService.idl", "nsISupports", "Scriptable", "1.7", "本接口是目录服务用于得到文件位置的函数。") }}</p>
<p><code>nsIDirectoryServiceProvider</code>.</p>
<h2 id="Method_overview" name="Method_overview">方法概览</h2>
<table class="standard-table">
  <tbody>
    <tr>
      <td><code>nsIFile <a href="#getFile()">getFile</a>(in string prop, out PRBool persistent);</code></td>
    </tr>
  </tbody>
</table>
<h2 id="Methods" name="Methods">方法</h2>
<h3 id="getFile()" name="getFile()">getFile()</h3>
<p>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.</p>
<pre class="eval">
nsIFile getFile(
  in string prop,
  out PRBool persistent
);
</pre>
<h6 id="Parameters" name="Parameters">Parameters</h6>
<dl>
  <dt>
    <code>prop</code></dt>
  <dd>
    The symbolic name of the file.</dd>
  <dt>
    <code>persistent</code></dt>
  <dd>
    <code>true</code> if the returned file will be cached by Directory Service. Subsequent requests for this prop will bypass the provider and use the cache. <code>false</code> if the provider will be asked for this prop each time it is requested.</dd>
</dl>
<h6 id="Return_value" name="Return_value">Return value</h6>
<p>The {{ Interface("nsIFile") }} represented by the property.</p>
<h2 id="Example" name="Example">示例</h2>
<p>This code creates a global, read-only string called <code>currDir</code> with the value of the current working directory.</p>
<pre class="eval">
 __defineGetter__("currDir",
                  function getCurrDir() {
                    return Components.classes["@mozilla.org/file/directory_service;1"]
                                     .getService(Components.interfaces.nsIDirectoryServiceProvider)
                                     .getFile("CurWorkD",{}).path;
                   });
</pre>
<p>Test it with to see the magic happen.</p>
<pre class="eval">
 alert(currDir);
</pre>
<h2 id="See_also" name="See_also">参见</h2>
<ul>
  <li><a href="/en/nsDirectoryService" title="en/nsDirectoryService">nsDirectoryService</a></li>
  <li>{{ Interface("nsIDirectoryService") }}</li>
  <li>其它目录服务关键字见[url=http://mxr.mozilla.org/mozilla-central/source/xpcom/io/nsDirectoryServiceDefs.h]nsDirectoryServiceDefs.h[/url]</li>
</ul>
<p>Additionally, see <a class="external" href="http://mb.eschew.org/16.php#sub_16.5.2">section 16.5.2</a> of the <a class="external" href="http://mb.eschew.org/">Rapid Application Development with Mozilla</a> book for instructions on how to get the <strong>current working directory</strong> and the <strong>process binary directory</strong>, among other things.</p>
恢复到这个版本