When utilizing CFolderPickerDialog
in a MFC application, is there any way I can view the files as well. I understand that there are way cool options to select a folder, but I need to make sure the files I want are in that directory as well. Any help would be greatly appreciated.
Asked
Active
Viewed 1,936 times
2

Mykola
- 3,343
- 6
- 23
- 39

Michael Boterf
- 51
- 8
1 Answers
-1
The CFolderPickerdialog
not allowing users to see the files within the dialog box came as a WYSIWYG moment. SO your option then becomes to utilize the CFileDialog
and then trim the path
to Folderpath
as described in the code below.
CFileDialog dlg (OFNHIDERADONLY | OFN_OVERWRITEPROMPT | BIF_BROWSEINCLUDEFILES, NULL);
...
CString path = dlg.GetPathName();
CString Folderpath = path.Left(path.ReverseFind('\\'));
if (Folderpath.Right(1) != "\\")
Folderpath += "\\";
Therefore, your code may look like C:\Users\foldername\file.txt
but will now look like this C:\Users\foldername\

Michael Boterf
- 51
- 8
-
This does not appear to be a proper solution. Requesting the user to pick a folder, and then have them select a **file** inside the folder is pretty counter-intuitive. A solution would be to use [IFileDialog](https://msdn.microsoft.com/en-us/library/windows/desktop/bb775966.aspx) with the `FOS_PICKFOLDERS` [FILEOPENDIALOGOPTIONS enumeration](https://msdn.microsoft.com/en-us/library/windows/desktop/dn457282.aspx) value. – IInspectable Jan 02 '16 at 01:00
-
Either way, the code you posted as a solution doesn't even compile. There is no `OFNHIDERADONLY`, and mixing the `OPENFILENAME` *Flags* with *ulFlags* from the [BROWSEINFO](https://msdn.microsoft.com/en-us/library/windows/desktop/bb773205.aspx) structure isn't going to end well either. There is also no `CFileDialog` c'tor taking the argument types you propose. – IInspectable Jan 08 '16 at 19:33
-
What's the reason for mixing unrelated flags? I cannot think of a single valid reason to do so. Generally, answers on SO should not be of the type *"you can work out the rest"*. Answers are supposed to be complete. As posted, it is not useful, and I'm afraid I'll have to vote accordingly. – IInspectable Jan 08 '16 at 23:32