Skip to content

launch() cannot locate files with spaces in the name on Windows #2994

Closed

Description

@wireddown

Related to #2868 but with files and locate=True

Problem

When a Windows program uses click.launch(some_path, locate=True) and some_path contains spaces, then Windows Explorer opens showing the user's Documents folder and not the specified file.

Dispatching the call to powershell and not cmd seems to fix the problem.

Reproduction

# Prepare and enter the virtual environment
mkdir click-demo
cd click-demo
python -m venv --upgrade-deps .venv
.\.venv\Scripts\activate.ps1

# Check versions
pip -V
# pip 25.1.1 from X:\scratch\click-demo\.venv\Lib\site-packages\pip (python 3.11)

# Install click
pip install click

# Check environment
pip list
# Package    Version
# ---------- -------
# click      8.2.1
# colorama   0.4.6
# pip        25.1.1
# setuptools 80.9.0

click-demo.py

import pathlib
import subprocess

import click

# No spaces in this path
root_folder = pathlib.Path("C:\\Users\\Public")

# No spaces in this path
succeeding_folder = root_folder / "click-demo"
succeeding_folder.mkdir(exist_ok=True)
click.launch(str(succeeding_folder), locate=True)

# Path has spaces!
failing_folder = root_folder / "click demo"
failing_folder.mkdir(exist_ok=True)
click.launch(str(failing_folder), locate=True)

# Wrap with powershell
subprocess.run(
    [
        "powershell",
        "-Command",
        f"explorer /select,{failing_folder!s}",
    ],
    check=True,
)

Environment:

  • Python version: 3.11.9
  • Click version: 8.2.1

Activity

  1. changed the title [-]Windows: `click.launch()` cannot locate files with spaces in the name for version 8.2.1[/-] [+]`launch()` cannot locate files with spaces in the name on Windows[/+] on Jul 4, 2025
  2. davidism commented on Jul 4, 2025

    @davidism
    Member

    No need to use Powershell. The argument to /select needs to be quoted, as described here: https://www.geoffchappell.com/studies/windows/shell/explorer/cmdline.htm. Something like the following will probably work:

    f'/select,"{_unquote_file(url).replace('"', '""')}"'
  3. added this to the 8.2.2 milestone on Jul 4, 2025
  4. added
    windows
    on Jul 5, 2025
  5. modified the milestones: 8.2.2, on Jul 16, 2025
  6. removed this from the milestone on Aug 3, 2025
  7. added theissue type on Oct 4, 2025
  8. gilangjavier commented on Mar 23, 2026

    @gilangjavier
  9. added a commit that references this issue on Apr 20, 2026
    fad31e4
  10. deleted a comment from koushik717 on May 17, 2026
  11. added this to the 8.4.1 milestone on May 22, 2026
  12. locked as resolved and limited conversation to collaborators on Jul 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    windows

    Type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions