Flow-Launcher/Flow.Launcher · warning · COMException

Failed to parse file path

Error message

Failed to parse file path

What it means

Thrown as COMException carrying the file-parsing HRESULT when SHParseDisplayName(filePath, ...) fails. This runs after the folder PIDL was successfully parsed, so the directory resolved but the specific file inside it could not be converted to an ITEMIDLIST. The HRESULT identifies the precise shell failure.

Source

Thrown at Flow.Launcher.Infrastructure/Win32Helper.cs:874

        #region Explorer

        // https://learn.microsoft.com/en-us/windows/win32/api/shlobj_core/nf-shlobj_core-shopenfolderandselectitems

        public static unsafe void OpenFolderAndSelectFile(string filePath)
        {
            ITEMIDLIST* pidlFolder = null;
            ITEMIDLIST* pidlFile = null;

            var folderPath = Path.GetDirectoryName(filePath);

            try
            {
                var hrFolder = PInvoke.SHParseDisplayName(folderPath, null, out pidlFolder, 0, out _);
                if (hrFolder.Failed) throw new COMException("Failed to parse folder path", hrFolder);

                var hrFile = PInvoke.SHParseDisplayName(filePath, null, out pidlFile, 0, out _);
                if (hrFile.Failed) throw new COMException("Failed to parse file path", hrFile);

                var hrSelect = PInvoke.SHOpenFolderAndSelectItems(pidlFolder, 1, &pidlFile, 0);
                if (hrSelect.Failed) throw new COMException("Failed to open folder and select item", hrSelect);
            }
            finally
            {
                if (pidlFile != null) PInvoke.CoTaskMemFree(pidlFile);
                if (pidlFolder != null) PInvoke.CoTaskMemFree(pidlFolder);
            }
        }

        #endregion

        #region Win32 Dark Mode

        /*
         * Inspired by https://github.com/ysc3839/win32-darkmode
         */

View on GitHub (pinned to 7fc63b07bb)

Solutions

  1. Verify File.Exists(filePath) immediately before calling OpenFolderAndSelectFile (the file may have been removed since the result was generated).
  2. Decode the HRESULT (0x80070002 file-not-found, 0x80070003 path-not-found, 0x80070005 access-denied) for specifics.
  3. If the file was renamed, refresh the result list before retrying.
  4. Trim trailing whitespace/slashes from the path before parsing.

Example fix

// before
var hrFile = PInvoke.SHParseDisplayName(filePath, null, out pidlFile, 0, out _);
if (hrFile.Failed) throw new COMException("Failed to parse file path", hrFile);

// after — existence check + graceful fallback
if (!File.Exists(filePath))
{
    // open the folder instead of selecting a missing file
    PInvoke.SHParseDisplayName(folderPath, null, out pidlFile, 0, out _);
}
else
{
    var hrFile = PInvoke.SHParseDisplayName(filePath, null, out pidlFile, 0, out _);
    if (hrFile.Failed) throw new COMException("Failed to parse file path", hrFile);
}
Defensive patterns

Strategy: validation

Validate before calling

if (!File.Exists(filePath))
{ // open folder alone instead of selecting a missing file
  Process.Start("explorer.exe", Path.GetDirectoryName(filePath)); return; }

Type guard

null

Try / catch

try { Win32Helper.OpenFolderAndSelectFile(filePath); }
catch (COMException ex) when (ex.Message.Contains("file path"))
{ Log.Warn(...); Process.Start("explorer.exe", $"/select,\"{filePath}\""); }

Prevention

When it happens

Trigger: The file portion of filePath does not exist (folder exists but file was deleted between enumeration and selection); filePath points to a virtual item the shell cannot parse; the path has trailing characters/spaces that break parsing; the file is on a disconnected network location; permission denied to enumerate the file's PIDL.

Common situations: OpenFolderAndSelectFile invoked on a stale result whose target file was renamed/deleted/moved; race between the search index and the filesystem; a file path with a trailing slash or space; recently-unmounted drive where the folder cached but the file is unreachable.

Understand the failure class

Related errors


AI-assisted analysis of Flow-Launcher/Flow.Launcher@7fc63b07bb (2026-08-13). Data as JSON: /api/errors/8d5531f7d0467f6c. Report an issue: GitHub.