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"
[TC 11.55rc7] Extra Quote Appended in %P Parameter Expansion
Moderators: Hacker, petermad, Stefan2, white
-
- New Member
- Posts: 1
- Joined: 2025-06-20, 06:44 UTC
- ghisler(Author)
- Site Admin
- Posts: 50873
- Joined: 2003-02-04, 09:46 UTC
- Location: Switzerland
- Contact:
Re: [TC 11.55rc7] Extra Quote Appended in %P Parameter Expansion
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.
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.
Author of Total Commander
https://www.ghisler.com
https://www.ghisler.com
Re: [TC 11.55rc7] Extra Quote Appended in %P Parameter Expansion
If "%P." does not work, the trailing backslash can be removed by using: "%P:~0,-1"
License #524 (1994)
Danish Total Commander Translator
TC 11.55rc4 32+64bit on Win XP 32bit & Win 7, 8.1 & 10 (22H2) 64bit, 'Everything' 1.5.0.1393a
TC 3.60b4 on Android 6, 13, 14
TC Extended Menus | TC Languagebar | TC Dark Help | PHSM-Calendar
Danish Total Commander Translator
TC 11.55rc4 32+64bit on Win XP 32bit & Win 7, 8.1 & 10 (22H2) 64bit, 'Everything' 1.5.0.1393a
TC 3.60b4 on Android 6, 13, 14
TC Extended Menus | TC Languagebar | TC Dark Help | PHSM-Calendar
- ghisler(Author)
- Site Admin
- Posts: 50873
- Joined: 2003-02-04, 09:46 UTC
- Location: Switzerland
- Contact:
Re: [TC 11.55rc7] Extra Quote Appended in %P Parameter Expansion
Yes, but then it wouldn't work with the root directory.
Author of Total Commander
https://www.ghisler.com
https://www.ghisler.com
Re: [TC 11.55rc7] Extra Quote Appended in %P Parameter Expansion
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.
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.