nsDirectoryService

  • Revision slug: nsDirectoryService
  • Revision title: nsDirectoryService
  • Revision id: 103821
  • Created:
  • Creator: trevorh
  • Is current revision? Yes
  • Comment Minor cleanup templates; 34 words added, 8 words removed

Revision Content

{{ Xpcomapi() }}

Summary

The XPCOM Directory Service. This service returns the locations of "well known" directories in an OS-independent manner. For instance, it can give you the path of the system's temporary directory, desktop directory, current working directory, and so on.

{{ ComponentSummary("f00152d0-b40b-11d3-8c9c-000064657374", "@mozilla.org/file/directory_service;1") }}

Supported Interfaces

  • {{ interface("nsIProperties") }}
  • {{ interface("nsIDirectoryService") }}

     

    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 {{ source("xpcom/io/nsDirectoryServiceDefs.h","nsDirectoryServiceDefs.h") }} along with a number of other Directory Service keys.

    See Also

Revision Source

<p>{{ Xpcomapi() }}</p>
<h3 id="Summary" name="Summary">Summary</h3>
<p>The XPCOM Directory Service. This service returns the locations of "well known" directories in an OS-independent manner. For instance, it can give you the path of the system's temporary directory, desktop directory, current working directory, and so on.</p>
<p>{{ ComponentSummary("f00152d0-b40b-11d3-8c9c-000064657374", "@mozilla.org/file/directory_service;1") }}</p>
<h3 id="Supported_Interfaces" name="Supported_Interfaces">Supported Interfaces</h3>
<ul> <li><code>{{ interface("nsIProperties") }}</code></li> <li><code>{{ interface("nsIDirectoryService") }}</code> <p> </p> <h3 id="Remarks" name="Remarks">Remarks</h3> <p>This component is a singleton and should therefore be accessed via the XPCOM Service Manager.</p> <h3 id="Example_Code" 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 NS_OS_TEMP_DIR is defined in {{ source("xpcom/io/nsDirectoryServiceDefs.h","nsDirectoryServiceDefs.h") }} along with a number of other Directory Service keys.</p> <h3 id="See_Also" name="See_Also">See Also</h3> <ul> <li><a href="/en/Using_nsIDirectoryService" title="en/Using_nsIDirectoryService">Using nsIDirectoryService</a></li> <li>{{ ifmethod("nsIProperties","get") }}</li> <li>{{ interface("nsIDirectoryServiceProvider") }}</li> </ul> </li>
</ul>
Revert to this revision