nsDirectoryService

  • Revision slug: nsDirectoryService
  • Revision title: nsDirectoryService
  • Revision id: 103810
  • Created:
  • Creator: Dria
  • Is current revision? No
  • Comment /* See Also */

Revision Content

Summary

The XPCOM Directory Service.

 ClassID:    f00152d0-b40b-11d3-8c9c-000064657374
 ContractID: @mozilla.org/file/directory_service;1

Supported Interfaces

Remarks

This component is a singleton and should therefore be accessed via the XPCOM Service Manager.

Example Code

#include "nsXPCOM.h"
#include "nsCOMPtr.h"
#include "nsDirectoryServiceDefs.h"
#include "nsIServiceManager.h"
#include "nsIProperties.h"

/**
 * Get the location of the system's "temp" directory.
 */
nsresult GetTempDir(nsIFile **aResult)
{
  nsresult rv;

  nsCOMPtr<nsIServiceManager> svcMgr;
  rv = NS_GetServiceManager(getter_AddRefs(svcMgr));
  if (NS_FAILED(rv))
    return rv;

  nsCOMPtr<nsIProperties> directory;
  rv = svcMgr->GetServiceByContractID("@mozilla.org/file/directory_service;1",
                                      NS_GET_IID(nsIProperties),
                                      getter_AddRefs(directory));
  if (NS_FAILED(rv))
    return rv;
    
  rv = directory->Get(NS_OS_TEMP_DIR, NS_GET_IID(nsIFile), aResult);

  return rv;
}

Note that NS_OS_TEMP_DIR is defined in nsDirectoryServiceDefs.h along with a number of other Directory Service keys.

See Also

nsIProperties::get, nsIDirectoryServiceProvider

Revision Source

<h3 name="Summary"> Summary </h3>
<p>The XPCOM Directory Service.
</p>
<pre class="eval"> ClassID:    f00152d0-b40b-11d3-8c9c-000064657374
 ContractID: @mozilla.org/file/directory_service;1
</pre>
<h3 name="Supported_Interfaces"> Supported Interfaces </h3>
<h3 name="Remarks"> Remarks </h3>
<p>This component is a singleton and should therefore be accessed via the XPCOM Service Manager.
</p>
<h3 name="Example_Code"> Example Code </h3>
<pre>#include "nsXPCOM.h"
#include "nsCOMPtr.h"
#include "nsDirectoryServiceDefs.h"
#include "nsIServiceManager.h"
#include "nsIProperties.h"

/**
 * Get the location of the system's "temp" directory.
 */
nsresult GetTempDir(nsIFile **aResult)
{
  nsresult rv;

  nsCOMPtr&lt;nsIServiceManager&gt; svcMgr;
  rv = NS_GetServiceManager(getter_AddRefs(svcMgr));
  if (NS_FAILED(rv))
    return rv;

  nsCOMPtr&lt;nsIProperties&gt; directory;
  rv = svcMgr-&gt;GetServiceByContractID("@mozilla.org/file/directory_service;1",
                                      NS_GET_IID(nsIProperties),
                                      getter_AddRefs(directory));
  if (NS_FAILED(rv))
    return rv;
    
  rv = directory-&gt;Get(NS_OS_TEMP_DIR, NS_GET_IID(nsIFile), aResult);

  return rv;
}
</pre>
<p>Note that <code>NS_OS_TEMP_DIR</code> is defined in <a class="external" href="http://lxr.mozilla.org/mozilla/source/xpcom/io/nsDirectoryServiceDefs.h">nsDirectoryServiceDefs.h</a> along with a number of other Directory Service keys.
</p>
<h3 name="See_Also"> See Also </h3>
<p><a href="en/NsIProperties#get">nsIProperties::get</a>,
<a href="en/NsIDirectoryServiceProvider">nsIDirectoryServiceProvider</a>
</p>
Revert to this revision