How to open Explorer with a specific file selected?

前端 未结 4 1113
误落风尘
误落风尘 2020-12-08 00:01

I would like to code a function to which you can pass a file path, for example:

C:\\FOLDER\\SUBFOLDER\\FILE.TXT

and it would open Windows E

4条回答
  •  误落风尘
    2020-12-08 00:43

    To follow up on @Mahmoud Al-Qudsi's answer. when he says "launching the process", this is what worked for me:

    // assume variable "path" has the full path to the file, but possibly with / delimiters
    for ( int i = 0 ; path[ i ] != 0 ; i++ )
    {
        if ( path[ i ] == '/' )
        {
            path[ i ] = '\\';
        }
    }
    std::string s = "explorer.exe /select,\"";
    s += path;
    s += "\"";
    PROCESS_INFORMATION processInformation;
    STARTUPINFOA startupInfo;
    ZeroMemory( &startupInfo, sizeof(startupInfo) );
    startupInfo.cb = sizeof( STARTUPINFOA );
    ZeroMemory( &processInformation, sizeof( processInformation ) );
    CreateProcessA( NULL, (LPSTR)s.c_str(), NULL, NULL, FALSE, 0, NULL, NULL, &startupInfo, &processInformation );
    

提交回复
热议问题