I'm trying to use IFileDialog to select a folder and the following code does this just fine. The problem is I'd like to see certain file types as well as folders while browsing (such as *.txt). Is there a simple way to do this?
//g_path is a global which will contain the selected folders path
void PickContainer()
{
IFileDialog *pfd;
if (SUCCEEDED(CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pfd))))
{
DWORD dwOptions;
if (SUCCEEDED(pfd->GetOptions(&dwOptions)))
{
pfd->SetOptions(dwOptions | FOS_PICKFOLDERS);
}
if (SUCCEEDED(pfd->Show(NULL)))
{
IShellItem *psi;
if (SUCCEEDED(pfd->GetResult(&psi)))
{
if(!SUCCEEDED(psi->GetDisplayName(SIGDN_DESKTOPABSOLUTEPARSING, &g_path)))
{
MessageBox(NULL, "GetIDListName() failed", NULL, NULL);
}
psi->Release();
}
}
pfd->Release();
}
}
Once you opt for FOS_PICKFOLDERS
then you can't see files in the dialog, only folders. If you omit FOS_PICKFOLDERS
then you can't select folders, only files. The standard dialog does not support what you are asking. You could write you own dialog but I'd be inclined to find a way to organise your application to fit around the behaviour of the standard dialog.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With