nsDirectoryService 编辑
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.
- Class ID
- f00152d0-b40b-11d3-8c9c-000064657374
- ContractID
- @mozilla.org/file/directory_service;1
Supported Interfaces
nsIProperties
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 nsDirectoryServiceDefs.h along with a number of other Directory Service keys.
See Also
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论