Flow-Launcher/Flow.Launcher · warning · COMException

Failed to parse folder path

Error message

Failed to parse folder path

What it means

Thrown as COMException with the folder-parsing HRESULT when SHParseDisplayName(folderPath, ...) returns a failed HRESULT. SHParseDisplayName converts a parsing name (path) to an ITEMIDLIST; failure means the shell could not resolve the directory part of the supplied file path. The HRESULT is included as the error code so the exact shell failure is identifiable.

Source

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

        }

        #endregion

        #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

View on GitHub (pinned to 7fc63b07bb)

Solutions

  1. Confirm the parent directory of filePath exists before calling OpenFolderAndSelectFile.
  2. Check the HRESULT in the exception (e.g. 0x80070002 = ERROR_FILE_NOT_FOUND, 0x80070003 = ERROR_PATH_NOT_FOUND) to pinpoint the shell error.
  3. For network paths, ensure the share is online and accessible.
  4. Guard against null folderPath (Path.GetDirectoryName can return null) before invoking the shell API.

Example fix

// before
var folderPath = Path.GetDirectoryName(filePath);
var hrFolder = PInvoke.SHParseDisplayName(folderPath, null, out pidlFolder, 0, out _);
if (hrFolder.Failed) throw new COMException("Failed to parse folder path", hrFolder);

// after — pre-validate and handle null
var folderPath = Path.GetDirectoryName(filePath);
if (string.IsNullOrEmpty(folderPath) || !Directory.Exists(folderPath))
    return; // or fall back to Process.Start("explorer.exe", ...)
var hrFolder = PInvoke.SHParseDisplayName(folderPath, null, out pidlFolder, 0, out _);
if (hrFolder.Failed) throw new COMException("Failed to parse folder path", hrFolder);
Defensive patterns

Strategy: validation

Validate before calling

var folder = Path.GetDirectoryName(filePath);
if (string.IsNullOrEmpty(folder) || !Directory.Exists(folder))
    return;

Type guard

null

Try / catch

try { Win32Helper.OpenFolderAndSelectFile(filePath); }
catch (COMException ex) when (ex.Message.Contains("folder path"))
{ Log.Warn(...); Process.Start("explorer.exe", Path.GetDirectoryName(filePath)); }

Prevention

When it happens

Trigger: The directory portion of filePath does not exist or is not a valid shell namespace; folderPath is null (Path.GetDirectoryName returned null for a root/invalid file path); the folder is on a disconnected network drive; the path contains illegal characters the shell rejects; insufficient permission to parse the namespace.

Common situations: OpenFolderAndSelectFile called with a path whose parent directory was deleted/moved; a UNC path to an offline share; a recently-removed USB drive; a path built from a stale MRU/recent-items list; a file path with no directory component (bare root).

Understand the failure class

Related errors


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