To be clear, I am no longer having a problem making my script do what I want. The
%Y parameter allowed me to fix it, and even add a new feature to it.
I am only continuing to post in this thread to help fix what seems to be a bug in Total Commander's handling of parameters.
ghisler(Author) wrote: 2023-03-09, 11:28 UTC
What would be the alternative? For example, when %F isn't the last parameter, I can't just leave it out because it would shift all parameters behind it by one.
I understand what you mean, however the issue of parameters being empty and messing up the order of parameters received by a script or external program is separate from the bug.
The Bug:
If you have the option to show the parent directory
[..] in the root of the drive, and you leave the cursor on that line, with no files selected, the parameter
%F will be empty, which is expected behavior. However what is
not expected is that no matter what order the parameters are in, this will cause
ALL of the parameters to be blank.
Create the following batch file;
Code: Select all
@echo off
echo 1) %1 - 2) %2 - 3) %3
pause
Create a button/command that points to this BAT file and include the parameters
%P %T %N. Make sure no files are selected, put the cursor on
[..] and invoke it. It should print something like;
1) C:\ - 2) E:\ - 3)
It prints the source and target directories, while the third one, the filename under the cursor is blank. This is the expected behavior.
Now change the parameters to
%P %T %F, make sure no files are selected, put the cursor on
[..] and invoke it. You will get;
1) - 2) - 3)
Because
all the parameters are blank. Instead of only
%F being blank, it causes
%P and
%T to blank as well. This is not the expected behavior. The results
should have been identical to the first example. That
%F is empty shouldn't cause other parameters to be empty was well. Total Commander should still send their values.
The problem of empty parameters messing up the order on the command line:
This is a separate issue that I don't consider a bug, it's simply something that people may not anticipate. If you change the above parameters to
%P %N %T and invoke it with the cursor on
[..], you will get something like this;
1) C:\ - 2) E:\ - 3)
Because
%N was empty and therefore nothing was printed to the command line between the source and target directories, so the
third parameter became the
second. Again, this is
NOT a bug, and I am
NOT complaining about this. This is completely expected behavior. I am posting this only for the purpose of discussing it.
I believe I may have a way to keep this from happening. It's a little unorthodox, so I understand completely if you don't want to use it. I only offer it here as one possible way to avoid this problem.
You can fill empty parameters with [space]^^[/space]. This counts as something to Windows, however since the caret is an escape character, it will be ignored on the command line. If you change the parameters in the above example to
%P ^^ %T, you should get;
1) C:\ - 2) - 3) E:\
The second is blank, but the caret acted as a placeholder. To verify this, I tested it with a command that is very particular about the order of its command line arguments. If the third parameter had been shifted to the left to fill the gap caused by a missing second parameter, it would have failed. The command worked perfectly.
Two carets are needed because the first escapes the second leaving a single caret, however when that single caret is printed to the command line, it escapes nothing and essentially doesn't exist. The spaces before and after them are important, otherwise they will be interpreted as part of the parameters that they are touching.
As I said, I don't consider blank
%N or
%Fparameters to be a bug, it's just something that people might not think of.