Page 1 of 1

[TC 11.55rc7] Extra Quote Appended in %P Parameter Expansion

Posted: 2025-06-20, 06:58 UTC
by deliciousscrewssss
Bug Report: Extra Quote Appended in %P Parameter Expansion

Environment
TC 11.55rc7 (almost all previous versions dating back to much earlier releases?)
OS: Windows 11 pro 22H2 22621.4317
Windows Terminal: 10.0.22621.4317

Issue Description
When configuring a toolbar button in Total Commander to launch Windows Terminal (wt) with the active panel's path as the starting directory using the parameter -d "%P", an extra double quote (") is appended to the expanded path. This results in an invalid command (e.g., wt -d "p:\#2""), causing Windows Terminal to fail with the error:
[error 2147942667 (0x8007010b)] Could not access starting directory "p:\#2""

Using the incomplete quote parameter -d "%P (missing closing quote) unexpectedly works, generating a valid command (e.g., wt -d "p:\#2"). This configuration correctly sets the starting directory for paths with or without spaces, such as:
p:\#2 (contains #)
c:\Microsoft Shared\Phone Tools (contains spaces)

Steps to Reproduce
In Total Commander, add a toolbar button with:
Command: wt
Parameters: -d "%P"

Re: [TC 11.55rc7] Extra Quote Appended in %P Parameter Expansion

Posted: 2025-06-20, 07:56 UTC
by ghisler(Author)
Total Commander does not pass an extra double quote to wt. You can test this yourself by adding a question mark to the start of the parameters field:
Command: wt
Parameters: ?-d "%P"
This will display the parameters which will be passed to the launched program.

I have also checked it in the debugger: Total Commander calls ShellExecuteEx with these fields:
lpVerb: NULL
lpFile: wt
lpParameters: -d "c:\directory name\"
lpDirectory: c:\current directory

The problem seems to be in wt.exe, it can't handle the trailing backslash.

Solution: change the parameter to:
Parameters: ?-d "%P."
The dot means "current directory".

This way Total Commander will pass
-d "c:\directory name\."
to wt.exe, which seems to work fine.

Re: [TC 11.55rc7] Extra Quote Appended in %P Parameter Expansion

Posted: 2025-06-20, 08:32 UTC
by petermad
If "%P." does not work, the trailing backslash can be removed by using: "%P:~0,-1"

Re: [TC 11.55rc7] Extra Quote Appended in %P Parameter Expansion

Posted: 2025-06-20, 09:07 UTC
by ghisler(Author)
Yes, but then it wouldn't work with the root directory.

Re: [TC 11.55rc7] Extra Quote Appended in %P Parameter Expansion

Posted: 2025-06-20, 09:45 UTC
by white
As discussed on this forum before, the reason for this is because that program (among other programs) parses the parameters like explained here:
https://learn.microsoft.com/en-us/cpp/cpp/main-function-command-line-args?view=msvc-170#parsing-c-command-line-arguments
https://learn.microsoft.com/en-us/dotnet/api/system.environment.getcommandlineargs?view=net-9.0

You can simply add a space at the end (before the quote) so the backslash is not longer the last character before the double quote.
When there is always exactly one backslash at the end, you can also choose to add a backslash, like suggested here.

As I earlier said here, the way arguments are parsed in Windows is left up to the program being launched. This makes it messy and inconsistent and Microsoft Windows programs also don’t use a consistent way of parsing arguments.

Re: [TC 11.55rc7] Extra Quote Appended in %P Parameter Expansion

Posted: 2025-06-20, 13:31 UTC
by deliciousscrewssss
I asked AI before, but couldn't find any solutions. It seems the issue really lies with wt.
You guys are really amazing—all the solutions worked. :-)