Invalid return of the last characters for the button parameters
Moderators: petermad, Stefan2, white, Hacker
Invalid return of the last characters for the button parameters
C:\dir\Name.ext under the cursor.
Results:
%P:~-1 = \
%P:~-2 = r\
%P:~-3 = ir
%P:~-4 = di
%P:~-5 = \d
etc.
%N:~-1 = t
%N:~-2 = xt
%N:~-3 = ex
%N:~-4 = .e
%N:~-5 = e.
etc.
%O:~-1 = e
%O:~-2 = me
%O:~-3 = am
%O:~-4 = Na
%O:~-5 = Na
etc.
Results:
%P:~-1 = \
%P:~-2 = r\
%P:~-3 = ir
%P:~-4 = di
%P:~-5 = \d
etc.
%N:~-1 = t
%N:~-2 = xt
%N:~-3 = ex
%N:~-4 = .e
%N:~-5 = e.
etc.
%O:~-1 = e
%O:~-2 = me
%O:~-3 = am
%O:~-4 = Na
%O:~-5 = Na
etc.
Overquoting is evil! 👎
- ghisler(Author)
- Site Admin
- Posts: 50254
- Joined: 2003-02-04, 09:46 UTC
- Location: Switzerland
- Contact:
Re: Invalid return of the last characters for the button parameters
The syntax is ~start,length but you only specified ~start which is undefined. What should it do?
From the help:
1. Batch files insert the entire rest of the string from the given start position. For example,
echo %ComSpec:~3%
returns
WINDOWS\system32\cmd.exe
2. In the multi-rename tool, [N3] only inserts the 3rd character.
From the help:
There are two possibilities:Note: All parameters now support substring fields in the form :~start,length, e.g. %N:~2,5 or %N:~-8,5 . To append a number directly after the length value, use another ~ character, e.g. %N:~2,5~2. Negative values are measured from the end of the string. Example: %P:~0,-1 cuts off the backslash from the path.
The Start value -0 is special: %N:~-0,20 copies the first 20 characters of the name without extension, %N:~-0,-20 the first 20 characters of the extension without the name.
1. Batch files insert the entire rest of the string from the given start position. For example,
echo %ComSpec:~3%
returns
WINDOWS\system32\cmd.exe
2. In the multi-rename tool, [N3] only inserts the 3rd character.
Author of Total Commander
https://www.ghisler.com
https://www.ghisler.com
Re: Invalid return of the last characters for the button parameters
The title of the topic reads: "... the last characters for the button parameters".What should it do?
Obviously, the behavior should match cmd. echo %ComSpec:~-3% returns 'exe', as expected.
Green indicates correct behavior, red indicates incorrect behavior. I thought it was also obvious.
Overquoting is evil! 👎
Re: Invalid return of the last characters for the button parameters
Since the implementation is very similar to cmd.exe, I think user expectation will often be that TC behaves the same way. Furthermore substring functions in various programming languages work that way when you leave out the length parameter. The use of the comma strengthens this expectation.
I don't think you can really compare it to the placeholders in the multi rename-tool (MRT). For starters, [N1] means the first character, while :~1 means the second character. That alone sets it apart completely. Furthermore, the placeholders in the MRT not only have a syntax with a comma, but also with a minus sign (2-5 means characters 2 to 5), and the syntax for taking the remaining characters is using the minus sign without a number following it.
I think the only reason that makes sense for assuming 1 character when no length is specified, is for compatibility reasons. Although the functionality was undocumented, it partially worked that way and people may be using it. Note that when using a positive index number higher than 9, it also fails (for example %N:~10).
All things considered, I would still choose for the syntax similar to cmd.exe.
I don't think you can really compare it to the placeholders in the multi rename-tool (MRT). For starters, [N1] means the first character, while :~1 means the second character. That alone sets it apart completely. Furthermore, the placeholders in the MRT not only have a syntax with a comma, but also with a minus sign (2-5 means characters 2 to 5), and the syntax for taking the remaining characters is using the minus sign without a number following it.
I think the only reason that makes sense for assuming 1 character when no length is specified, is for compatibility reasons. Although the functionality was undocumented, it partially worked that way and people may be using it. Note that when using a positive index number higher than 9, it also fails (for example %N:~10).
All things considered, I would still choose for the syntax similar to cmd.exe.
Re: Invalid return of the last characters for the button parameters
Yes, it's like str.slice([-]start[, length]) in JS or Mid(Str, start[, length]) in VB, where the second parameter is optional.
Overquoting is evil! 👎
Re: Invalid return of the last characters for the button parameters
"People" may think this is a suggestion, but not a bug, so move it to forum suggestions...
Re: Invalid return of the last characters for the button parameters
For me, this is definitely a bug, because there is a violation of the consistency of right and wrong behavior, which is reflected in the examples.
Overquoting is evil! 👎
- ghisler(Author)
- Site Admin
- Posts: 50254
- Joined: 2003-02-04, 09:46 UTC
- Location: Switzerland
- Contact:
Re: Invalid return of the last characters for the button parameters
This should be fixed in RC3, please test it!
26.01.25 Fixed: Button bar, partial parameters like %P:start,len: If len isn't specified, keep all characters until the end, e.g. %P:4 (32/64)
Author of Total Commander
https://www.ghisler.com
https://www.ghisler.com
Re: Invalid return of the last characters for the button parameters
Tested OK using TC 11.51rc3 32-bit and 64-bit.
Re: Invalid return of the last characters for the button parameters
Yes, it's fixed. Thanks!
The character '~' is missing:
Related question: is it correct to leave quotation marks for parameters like %N:~<s>,<l> (%V, %C1, %R1, %S1), even if there are spaces left?
In theory, quotation marks are only needed for existing files/folders. Why use quotation marks for changed names? I think they should be removed, regardless of the presence of %Q.
The character '~' is missing:
It's also worth pointing out in the help that <start> can be negative for capturing the last characters.
Related question: is it correct to leave quotation marks for parameters like %N:~<s>,<l> (%V, %C1, %R1, %S1), even if there are spaces left?
In theory, quotation marks are only needed for existing files/folders. Why use quotation marks for changed names? I think they should be removed, regardless of the presence of %Q.
Overquoting is evil! 👎
- ghisler(Author)
- Site Admin
- Posts: 50254
- Joined: 2003-02-04, 09:46 UTC
- Location: Switzerland
- Contact:
Re: Invalid return of the last characters for the button parameters
Thanks for confirming the fix!
Fixed in the online history1151.txt.The character '~' is missing:
Already explained in the help, it also works for <length>, which is then measured from the end of the file:It's also worth pointing out in the help that <start> can be negative for capturing the last characters.
Code: Select all
Negative values are measured from the end of the string.
Yes, quotes are used when the resulting string contains at least one space. It has nothing to do with existing or not existing files, but with the separation of command lines into multiple parts by cmd.exe.Related question: is it correct to leave quotation marks for parameters like %N:~<s>,<l> (%V, %C1, %R1, %S1), even if there are spaces left?
Author of Total Commander
https://www.ghisler.com
https://www.ghisler.com
Re: Invalid return of the last characters for the button parameters
OK. Sorry, I accidentally opened the previous version.Already explained in the help,
I understand that. But when the string is changed, only a substring remains, which participates in merging with custom substrings. Therefore, it's correct that quotes for the user remain optional, i.e. "Prefix%N:~-4Suffix".but with the separation of command lines into multiple parts by cmd.exe.
You didn't add quotation marks for %O and %E, which are also substrings, so the same logic should apply here.
Or imagine that you need to write cmd /c if "%N:~,5"=="Pref " copy %N "%T"
I don't think it makes sense to add %Q to every such entry, since this will have to be done all the time.
Overquoting is evil! 👎
- ghisler(Author)
- Site Admin
- Posts: 50254
- Joined: 2003-02-04, 09:46 UTC
- Location: Switzerland
- Contact:
Re: Invalid return of the last characters for the button parameters
Sorry, there are too many cases to decide when to add quotes and when not. If you don't like the quotes, just use %Q once and all automatic quotation marks will be omitted. automatic quotes are only added to %N, %M, and their combinations with %P and %T, plus %S and %R.
Since the original bug was fixed, I'm moving this thread to fixed bugs.
Since the original bug was fixed, I'm moving this thread to fixed bugs.
Moderator message from: ghisler(Author) » 2025-01-30, 08:11 UTC
Moved to fixed bugs
Author of Total Commander
https://www.ghisler.com
https://www.ghisler.com
Re: Invalid return of the last characters for the button parameters
Have you read this? >If you don't like the quotes, just use %Q once and all automatic quotation marks will be omitted.
Fla$her wrote:I don't think it makes sense to add %Q to every such entry, since this will have to be done all the time.
It's not true.automatic quotes are only added to .. %M
Last edited by Fla$her on 2025-01-30, 16:10 UTC, edited 1 time in total.
Overquoting is evil! 👎
Re: Invalid return of the last characters for the button parameters
YES - as pointed out here a long time ago: viewtopic.php?t=76443It's not true.
When even the author cannot remember this inconsistency, perhaps it is time to make quoting of %N and %M consistent.
License #524 (1994)
Danish Total Commander Translator
TC 11.51rc2 32+64bit on Win XP 32bit & Win 7, 8.1 & 10 (22H2) 64bit, 'Everything' 1.5.0.1390a
TC 3.60b4 on Android 6, 13, 14
TC Extended Menus | TC Languagebar | TC Dark Help | PHSM-Calendar
Danish Total Commander Translator
TC 11.51rc2 32+64bit on Win XP 32bit & Win 7, 8.1 & 10 (22H2) 64bit, 'Everything' 1.5.0.1390a
TC 3.60b4 on Android 6, 13, 14
TC Extended Menus | TC Languagebar | TC Dark Help | PHSM-Calendar