Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the path of "my computer" folder on windows?

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.

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.

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

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

like image 264
dudu721 Avatar asked Mar 17 '16 15:03

dudu721


People also ask

What is the path of a folder on Desktop?

The location of the Desktop folder in most versions of Windows is %USERPROFILE%\Desktop , which for most users becomes C:\Users\YOURUSERNAME\Desktop .

Where can I find the file path?

The file path is found at the top of the folder or webpage where you are viewing the file. For example: When viewing files in your web browser, the Google Drive file path is at the top of the Google Drive webpage.


1 Answers

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.

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();

Disclaimer: I couldn't find any relevant documentation for the virtual folder CLSID, or this behaviour of the File dialog. So this is most likely not contractual, and could possibly change in future versions of Windows.

like image 61
Luaan Avatar answered Nov 15 '22 20:11

Luaan