C++ - Shell API - Is there a way to convert a display file name to a parsed file name?

42 Views Asked by At

In the Windows Shell API, is there a way to convert a display file name to a parsed file name?

For example, I have an IDL located on an external storage with resolves to the following parsed name:

::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\\?\usb#vid_05ac&pid_12a8&mi_00#7&1a2090a1&0&0000#{6ac27878-a6fa-4155-ba85-f98f491d4f33}\SID-{10004,Internal Storage,64000000000}\{00000250-0000-0000-5002-000000000000}\{000002A2-0000-0000-A202-000000000000}

I can get the following display name from the same IDL:

This PC\Apple iPhone\Internal Storage\202212__\IMG_3295.MOV

Now I want to replace the above extension:

This PC\Apple iPhone\Internal Storage\202212__\IMG_3295.JPG

And check if the modified file name exists on my external storage, and if yes, to get the matching file IDL. The best way would be to have a function which convert the display name to a valid parsed name if the file exists, or an error if the file not exists.

Is there a way to do that, if possible in a simple manner (e.g. without iterate in an opened file iterator), considering that the performance is important?

1

There are 1 best solutions below

1
user23467867 On
  1. You need to create shell item from parsing name.
  2. Get display name from shell item

Here is pseudo code

IShellItem* pItem = nullptr;
hr = SHCreateItemFromParsingName(L"MyParsingPATH\\PARSING_NAME", NULL, IID_PPV_ARGS(&pItem));
if (SUCCEEDED(hr)) 
{
    LPWSTR pDisplayName = nullptr;
    hr = pItem->GetDisplayName(SIGDN_NORMALDISPLAY, &pDisplayName);
    if (SUCCEEDED(hr)) 
    {
       // ...
    }

}