“我的电脑"的路径是什么?windows上的文件夹? [英] What is the path of "my computer" folder on windows?

查看:75
本文介绍了“我的电脑"的路径是什么?windows上的文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Visual Studio IDE 处理 C++ windowsform 项目.
我使用 CFileDialog 类要求用户选择要打开的文件.它显示一个通常打开的文件选择窗口.我希望显示的默认文件夹与单击我的电脑"时访问的文件夹相同,其中显示了硬盘驱动器、USB 驱动器、DVD 驱动器等.

I am working on a C++ windowsform project, using visual Studio IDE.
I use CFileDialog class to ask the user to select a file to open. It display an usual open file selection windows. I would like the default folder displayed to be the same as the one accessed when clicked on "My computer", where the harddrives, USB drives, dvd drives etc. are displayed.

我可以通过将其路径写入lpstrInitialDir 成员来定义默认文件夹,但我找不到此类文件夹的路径.我尝试了\"、explorer.exe"、",但没有一个给我预期的结果.该应用程序将被多个用户使用,因此解决方案不得在路径中包含用户名.即C:\Documents and Settings[user]\Desktop\My Computer"可能有效,但不适用于我的应用程序.

I can define default folder by writting its path tolpstrInitialDir member, but I don't find the path for such a folder. I tried "\", "explorer.exe", "", none of them gave me the expected result. The application will be used by several users, so the solution must not include the user name in the path. i.e "C:\Documents and Settings[user]\Desktop\My Computer" may work but is not correct for my application.

有谁知道定义windows的根"路径(即C:\的根)?

Does anyone know of to define the "root" path of windows (i.e the root of C:\) ?

我在 SO 和 Internet 上进行了搜索,但可能因为找不到合适的内容而使用了错误的关键字.

I searched on SO and internet but maybe I have used wrong keywords because I couldn't find appropriate content.

推荐答案

My Computer 是一个不对应任何文件系统目录的虚拟外壳文件夹.没有与该位置对应的文件系统路径.

My Computer is a virtual shell folder that doesn't correspond to any file system directory. There's no file system path that would correspond to that location.

幸运的是,文件对话框确实会说shellese",因此您可以使用 shell 文件夹的 CLSID(不要与 GUID KNOWNFOLDERID 或 CSIDL 混淆).C# Winforms 中的示例,但实际上,唯一重要的部分是 ::CLSID):

Fortunately, file dialogs do speak "shellese", so you can use the CLSID (not to be confused with the GUID KNOWNFOLDERID or the CSIDL) of the shell folder. Sample in C# Winforms, but really, the only important part is the ::CLSID):

var ofd = new OpenFileDialog();
ofd.InitialDirectory = "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}";
ofd.ShowDialog();

免责声明:我找不到虚拟文件夹 CLSID 或文件对话框的这种行为的任何相关文档.所以这很可能不是合同规定的,并且可能会在未来的 Windows 版本中发生变化.

这篇关于“我的电脑"的路径是什么?windows上的文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆