TC32: If no files are selected, the %F parameter prevents all other parameters from being sent to the command line

Please report only one bug per message!

Moderators: white, Hacker, petermad, Stefan2

Rekrul
Junior Member
Junior Member
Posts: 69
Joined: 2007-11-04, 21:40 UTC

TC32: If no files are selected, the %F parameter prevents all other parameters from being sent to the command line

Post by *Rekrul »

If you have the option Show parent dir [..] also in root of drive enabled, and you invoke a command that uses the %F list parameter, along with ANY other parameters, but you don't have any files selected, or a file under the cursor, Total Commander doesn't send anything at all to the command line.

To reproduce this bug;

Go to Configuration > Options > Display, and check Show parent dir [..] also in root of drive.

Open Notepad and enter the following;

Code: Select all

@echo off
echo %1 %2 %3 %4
pause
Save it as test.bat, then create a new button on the Buttonbar that points to it, and include the parameters %P %T %N %F. Make sure that no files are selected and that the cursor is on the [..] at the top of the source window.

Instead of printing the source and target paths as expected, it will simply print ECHO is off., because nothing was sent to the command line. Now delete the %F parameter, then try it again, and it will print the source and target paths to the window, even though the %N parameter is as empty as %F was.

The contents (or lack thereof) of one parameter shouldn't negate the sending of completely separate parameters. As far as I can tell, %F is the only parameter that does this. %N doesn't interfere with other parameters, even if no files are seleceted/under the cursor.

I checked past versions of Total Commander, and it seems that it always behaved this way, at least back to v7.xx.

Of course, I know someone will ask why anyone would want to use the %F parameter, which creates a list of selected files, if no files are selected. The reason is as follows:

I made a script that converts files, and the button to call it is supposed to send both the target path and a list file, if anything was selected. The script checks to see if Total Commander sent it a list of files to process. If there's no list, it converts all the files in the directory. If I've selected any files, or even just left the cursor on a file, a list file will be created and sent to the script, and it will use that to only convert the selected files. It's meant to send the converted files to the target window, but that only works if I select the files. If I want it to do all the files without manually selecting them first, it puts the converted files in the same directory because it never receives the target path.
User avatar
Horst.Epp
Power Member
Power Member
Posts: 6429
Joined: 2003-02-06, 17:36 UTC
Location: Germany

Re: TC32: If no files are selected, the %F parameter prevents all other parameters from being sent to the command line

Post by *Horst.Epp »

Whats the real problem, you can see in your batch that the parameter is empty
and do nothing for example.
Windows 11 Home x64 Version 23H2 (OS Build 22631.3296)
TC 11.03 x64 / x86
Everything 1.5.0.1371a (x64), Everything Toolbar 1.3.2, Listary Pro 6.3.0.69
QAP 11.6.3.2 x64
User avatar
petermad
Power Member
Power Member
Posts: 14700
Joined: 2003-02-05, 20:24 UTC
Location: Denmark
Contact:

Re: TC32: If no files are selected, the %F parameter prevents all other parameters from being sent to the command line

Post by *petermad »

2Rekrul
It is not when there is no selected file in the active panel, but as you also point out yourself: when the cursot is placed on [..]-

Add %Y to the parameters field, and the problem is solved.
License #524 (1994)
Danish Total Commander Translator
TC 11.03 32+64bit on Win XP 32bit & Win 7, 8.1 & 10 (22H2) 64bit, 'Everything' 1.5.0.1371a
TC 3.50b4 on Android 6 & 13
Try: TC Extended Menus | TC Languagebar | TC Dark Help | PHSM-Calendar
Rekrul
Junior Member
Junior Member
Posts: 69
Joined: 2007-11-04, 21:40 UTC

Re: TC32: If no files are selected, the %F parameter prevents all other parameters from being sent to the command line

Post by *Rekrul »

Horst.Epp wrote: 2023-03-08, 13:34 UTC Whats the real problem, you can see in your batch that the parameter is empty
and do nothing for example.
The problem is that it doesn't send the target path if there's no list file.

When calling my script, it sends the parameters %T %F. My script takes the first one and puts it into a variable called %Dest%, then it takes the second one and puts it into a variable called %List%. That variable is then checked to see if it's empty. If it is, meaning nothing was selected, it jumps to the routine that steps through all the matching files in the directory and converts them, sending the converted files to %Dest%. However if %List% contains a path and filename of a list file, the script jumps to a routine that reads in that file, line by line, checks each one to make sure that it's a file that can be converted, and then converts them, sanding the output to %Dest%.

Unfortunately, the first case doesn't work correctly because if there's no list file, there's no target path. %Dest% will be empty because Total Commander didn't send anything at all to the command line after the name of the script. So instead of sending the converted files to the destination directory, they end up in the source directory with the original files.

If Total Commander doesn't append the target path to the command line, there's no possible way that my script can know what it is. I could put in an option to manually enter a destination, or I could hard-code a destination directory, but there's no way to have it automatically send the converted files to the other window, unless the %T parameter works.
Rekrul
Junior Member
Junior Member
Posts: 69
Joined: 2007-11-04, 21:40 UTC

Re: TC32: If no files are selected, the %F parameter prevents all other parameters from being sent to the command line

Post by *Rekrul »

petermad wrote: 2023-03-08, 14:29 UTC 2Rekrul
It is not when there is no selected file in the active panel, but as you also point out yourself: when the cursot is placed on [..]-
OK, but it's still a bug. If you send the parameters %T %N while nothing is selected and the cursor is on [..], it prints the target path. When you send %T %F it doesn't send anything. The fact that %F doesn't contain any value shouldn't negate the ending of other parameters.
petermad wrote: 2023-03-08, 14:29 UTC Add %Y to the parameters field, and the problem is solved.
Thank you, I didn't notice that in the help file. It will do what I want, but it's not a true fix. It causes a list file to always be created, even if it doesn't contain anything. I still maintain that parameters like %T should be sent to the command line regardless of whether or not %F is empty.
User avatar
petermad
Power Member
Power Member
Posts: 14700
Joined: 2003-02-05, 20:24 UTC
Location: Denmark
Contact:

Re: TC32: If no files are selected, the %F parameter prevents all other parameters from being sent to the command line

Post by *petermad »

2Rekrul
should be sent to the command line regardless of whether or not %F is empty.
I agree that it looks like a bug.
License #524 (1994)
Danish Total Commander Translator
TC 11.03 32+64bit on Win XP 32bit & Win 7, 8.1 & 10 (22H2) 64bit, 'Everything' 1.5.0.1371a
TC 3.50b4 on Android 6 & 13
Try: TC Extended Menus | TC Languagebar | TC Dark Help | PHSM-Calendar
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 48012
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Re: TC32: If no files are selected, the %F parameter prevents all other parameters from being sent to the command line

Post by *ghisler(Author) »

It will do what I want, but it's not a true fix. It causes a list file to always be created, even if it doesn't contain anything.
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.
Author of Total Commander
https://www.ghisler.com
User avatar
Hacker
Moderator
Moderator
Posts: 13040
Joined: 2003-02-06, 14:56 UTC
Location: Bratislava, Slovakia

Re: TC32: If no files are selected, the %F parameter prevents all other parameters from being sent to the command line

Post by *Hacker »

Christian,
I guess the most consistent solution would be to pass a list file, which is empty.

Roman
Mal angenommen, du drückst Strg+F, wählst die FTP-Verbindung (mit gespeichertem Passwort), klickst aber nicht auf Verbinden, sondern fällst tot um.
Rekrul
Junior Member
Junior Member
Posts: 69
Joined: 2007-11-04, 21:40 UTC

Re: TC32: If no files are selected, the %F parameter prevents all other parameters from being sent to the command line

Post by *Rekrul »

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.
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 48012
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Re: TC32: If no files are selected, the %F parameter prevents all other parameters from being sent to the command line

Post by *ghisler(Author) »

I have checked this now. The behaviour to send no parameters when the list would be empty is intentional. It was done so a program can be opened without files when the cursor is on [..] and with the selected files and instructions on how to handle them otherwise.

I will add a new parameter %y (lowercase) to keep the other parameters and just drop the list parameter when the list is empty.
Author of Total Commander
https://www.ghisler.com
User avatar
Horst.Epp
Power Member
Power Member
Posts: 6429
Joined: 2003-02-06, 17:36 UTC
Location: Germany

Re: TC32: If no files are selected, the %F parameter prevents all other parameters from being sent to the command line

Post by *Horst.Epp »

ghisler(Author) wrote: 2023-03-20, 08:08 UTC I have checked this now. The behaviour to send no parameters when the list would be empty is intentional. It was done so a program can be opened without files when the cursor is on [..] and with the selected files and instructions on how to handle them otherwise.

I will add a new parameter %y (lowercase) to keep the other parameters and just drop the list parameter when the list is empty.
Is it only me who dosn't understand this ?
What do you mean with "just drop the list parameter when the list is empty" ?
To my understanding an empty list should be delivered in this case.
Windows 11 Home x64 Version 23H2 (OS Build 22631.3296)
TC 11.03 x64 / x86
Everything 1.5.0.1371a (x64), Everything Toolbar 1.3.2, Listary Pro 6.3.0.69
QAP 11.6.3.2 x64
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 48012
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Re: TC32: If no files are selected, the %F parameter prevents all other parameters from being sent to the command line

Post by *ghisler(Author) »

To my understanding an empty list should be delivered in this case.
This is already supported with the %Y (uppercase) parameter.
Author of Total Commander
https://www.ghisler.com
Fla$her
Power Member
Power Member
Posts: 2227
Joined: 2020-01-18, 04:03 UTC

Re: TC32: If no files are selected, the %F parameter prevents all other parameters from being sent to the command line

Post by *Fla$her »

2Rekrul
Please provide a couple of real algorithms where you need parameters in the absence of selection. Curiously. Personally, I don't have such scripts, so I never needed %Y. It was enough to exit in the absence of parameters. Why continue if there is nothing to process?

ghisler(Author) wrote: 2023-03-20, 08:08 UTC I will add a new parameter %y (lowercase) to keep the other parameters and just drop the list parameter when the list is empty.
This is better than the behavior with %Y, especially since the list parameter can be put at the end with a check for its presence.
And why did you initially need an empty list? Maybe we should just change the behavior of %Y instead of adding a new parameter?
Overquoting is evil! 👎
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 48012
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Re: TC32: If no files are selected, the %F parameter prevents all other parameters from being sent to the command line

Post by *ghisler(Author) »

Please check whether the new %y parameter in TC11 beta behaves as described:
Added: Command line parameters (button bar, start menu): New parameter %y (lowercase) keeps other parameters and skips only list file parameters if the list is empty
Added: Command line parameters (button bar, start menu): Combined parameter %Y%y allows empty lists like %Y, but selects file under cursor if nothing is selected
Author of Total Commander
https://www.ghisler.com
Fla$her
Power Member
Power Member
Posts: 2227
Joined: 2020-01-18, 04:03 UTC

Re: TC32: If no files are selected, the %F parameter prevents all other parameters from being sent to the command line

Post by *Fla$her »

2ghisler(Author)
If (in the absence of selecting and setting the cursor to [..]) put %y in front of the list parameter with two letters (%WF/%WL/%UF/%UL), then the result is the character on the right (F/L).
Overquoting is evil! 👎
Post Reply