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
Related to #2868 but with files and
locate=TrueProblem
When a Windows program uses
click.launch(some_path, locate=True)andsome_pathcontains spaces, then Windows Explorer opens showing the user's Documents folder and not the specified file.Dispatching the call to
powershelland notcmdseems to fix the problem.Reproduction
click-demo.pyEnvironment: