Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix "Show in folder" on windows when path has spaces #3641

Merged
merged 1 commit into from
Dec 16, 2024

Conversation

iamllama
Copy link
Contributor

On windows, "Show in folder" opens the default (Documents) folder when someone with the default ("User 1") profile uses it on an image residing in the media folder

In this case, a typical media path would be C:\Users\name with spaces\AppData\Roaming\Anki2\User 1\collection.media\img.png

However,

Quotation marks are required if the File/Folder object contains spaces or symbols.
https://ss64.com/nt/explorer.html

But adding quotes around path, i.e.

subprocess.run(["explorer", f"/select,\"{path}\""], check=False)

breaks it for all paths, even those without spaces. I suspect the issue is improper command line quoting with the extra "s

As per microsoft/WSL#7603 (comment) and this SO answer, spliting off the path into its own arg lets it be quoted properly

NB:

subprocess.run(f"explorer /select,{path}", shell=True)

is an alternative, because the above-mentioned limitation doesn't apply to the shell, which correctly handles it regardless of spaces for some reason 😕

@iamllama iamllama changed the title Fix "Show in folder" on windows Fix "Show in folder" on windows when path has spaces Dec 16, 2024
Copy link
Collaborator

@abdnh abdnh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@abdnh abdnh merged commit a0712b0 into ankitects:main Dec 16, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants