User command stopped working

English support forum

Moderators: white, Hacker, petermad, Stefan2

User avatar
sidefx88
Senior Member
Senior Member
Posts: 294
Joined: 2007-04-11, 17:07 UTC
Location: Argentina

User command stopped working

Post by *sidefx88 »

Hi!

A few years ago I've implemented a user command on TC to swap the filenames of two selected files on the same panel.

fileA.jpg -> fileB.jpg
and
fileB.jpg -> fileA.jpg

It worked fine for years (maybe Windows 7 times), but now (Windows 10 times) I need to use it and it doesn't work anymore. The keyboard shortcut assigned to that user command is OK, but the command it self does just nothing (some icons on the screen flashes for a split second, no console shows up).

The code on "usercmd.ini" is this:

Code: Select all

[em_swapfilenames]
button=
cmd=cmd.exe /C
param=if "%p%s"=="%c1 %c2" ((move %C1 %c1.tempfile) && (move %C2 %C1) && (move %c1.tempfile %C2)) else ((echo You must select two files!) && (echo.) && pause)
Is there something wrong or that is not compatible with Windows 10?

I'm using TC 9.51 32-bit (with Admin rights) on Windows 10 Pro x64 20·04.

Thanks in advance!

Regards
I Love Total Commander!
User avatar
Hacker
Moderator
Moderator
Posts: 13052
Joined: 2003-02-06, 14:56 UTC
Location: Bratislava, Slovakia

Re: User command stopped working

Post by *Hacker »

sidefx88,
Try replacing

Code: Select all

cmd.exe /c
with

Code: Select all

cmd.exe /k
and see what happens.

HTH
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.
User avatar
sidefx88
Senior Member
Senior Member
Posts: 294
Joined: 2007-04-11, 17:07 UTC
Location: Argentina

Re: User command stopped working

Post by *sidefx88 »

Hacker, thanks for your answer.

The same thing happens.
When I select two files on the same panel and press the keyboard shortcut nothing happens, just a blink on:

· TC icon on the taskbar
· TC title bar
· TC menu bar
· TC line cursor

I've also checked that the keyboard shortcut be the unique. And run TC without admin rights. Same thing :(
I Love Total Commander!
User avatar
sidefx88
Senior Member
Senior Member
Posts: 294
Joined: 2007-04-11, 17:07 UTC
Location: Argentina

Re: User command stopped working

Post by *sidefx88 »

The only way to get a cmd console to show what is happening is to select two files and run the whole command:

"cmd.exe /k if "%p%s"=="%c1 %c2" ((move %C1 %c1.tempfile) && (move %C2 %C1) && (move %c1.tempfile %C2)) else ((echo You must select two files!) && (echo.) && pause)"

All I get is the text warning on the script: "You must select two files".
I Love Total Commander!
User avatar
Dalai
Power Member
Power Member
Posts: 9364
Joined: 2005-01-28, 22:17 UTC
Location: Meiningen (Südthüringen)

Re: User command stopped working

Post by *Dalai »

There is a closing bracket missing after the pause. If you only get an error, the culprit must be in the if condition. Try echoing out every variable. Or even better, add a question mark as the first parameter of the TC button. This way, the variables have their respective contents.

Regards
Dalai
#101164 Personal licence
Ryzen 5 2600, 16 GiB RAM, ASUS Prime X370-A, Win7 x64

Plugins: Services2, Startups, CertificateInfo, SignatureInfo, LineBreakInfo - Download-Mirror
User avatar
sidefx88
Senior Member
Senior Member
Posts: 294
Joined: 2007-04-11, 17:07 UTC
Location: Argentina

Re: User command stopped working

Post by *sidefx88 »

2dalai: Thanks for your answer

I'm counting the brackets for the 10th time and that seems to be OK: (( ) ( ) ( )) (( ) ( ))

Yes, the problem is on the IF part, but I don't get exactly where. Maybe the variables?

Sorry, but I didn't understand when you said "Try echoing out every variable" and "add a question mark as the first parameter of the TC button".
I Love Total Commander!
User avatar
Stefan2
Power Member
Power Member
Posts: 4132
Joined: 2007-09-13, 22:20 UTC
Location: Europa

Re: User command stopped working

Post by *Stefan2 »

That command stil works for me on win7:

Code: Select all

TOTALCMD#BAR#DATA
cmd /k
?if "%p%s"=="%c1 %c2" ((move %C1 %c1.tempfile) && (move %C2 %C1) && (move %c1.tempfile %C2)) else ((echo You must select two files!) && (echo.) && pause)
C:\Windows\system32\cmd.exe
Swap filename of both SELECTED files


-1
(that is an copy&paste-able TC-button code)



Preview:(arranged and colored)
if
"D:\d\5b\ACTIVE~1.EXE D:\d\5b\FOTO-F~1.PNG"
==
"D:\d\5b\ACTIVE~1.EXE D:\d\5b\FOTO-F~1.PNG" (

(move D:\d\5b\Active_Pixels.exe D:\d\5b\ACTIVE~1.EXE.tempfile) &&
(move D:\d\5b\Foto-Freeware.png D:\d\5b\Active_Pixels.exe) &&
(move D:\d\5b\ACTIVE~1.EXE.tempfile D:\d\5b\Foto-Freeware.png)

) else (
(echo You must select two files!) && (echo.) && pause
)

Result:

Code: Select all

        1 Datei(en) verschoben.
        1 Datei(en) verschoben.
        1 Datei(en) verschoben.

D:\d\5b>
File names of both selected files are swapped.



Try to disable the error-check and change every && to an single &




EDIT:
for information and clarification for other readers

That command above also works if the file names contains spaces,
as lower case %c use shortened 8.3 file name anyway, and upper case %C is correctly quoted by TC itself.
For more info about TC parameter click the {Help]-button in the open Button dialog.

if
"D:\d\5b\ACTIVE~1.EXE D:\d\5b\FOTOFR~1.PNG" ==
"D:\d\5b\ACTIVE~1.EXE D:\d\5b\FOTOFR~1.PNG" (
(move "D:\d\5b\Active Pixels.exe" D:\d\5b\ACTIVE~1.EXE.tempfile) &&
(move "D:\d\5b\Foto Freeware.png" "D:\d\5b\Active Pixels.exe") &&
(move D:\d\5b\ACTIVE~1.EXE.tempfile "D:\d\5b\Foto Freeware.png")
) else ((echo You must select two files!) && (echo.) && pause)



And about that &&-thingy:
CommandA & CommandB (the second command is run directly after the first)
CommandA && CommandB (the second command is only run if the first was successful)
For more info google for example for "Windows command prompt: CMD commands explained" by ionos com


 
User avatar
sidefx88
Senior Member
Senior Member
Posts: 294
Joined: 2007-04-11, 17:07 UTC
Location: Argentina

Re: User command stopped working

Post by *sidefx88 »

2Stefan2

Thanks for your answer

I've deleted all the "else......" part and changed all the && to a single &, and the problem persists. A command console windows shows up for a split second and then disappear. The filenames of the files remain the same.
I Love Total Commander!
User avatar
Dalai
Power Member
Power Member
Posts: 9364
Joined: 2005-01-28, 22:17 UTC
Location: Meiningen (Südthüringen)

Re: User command stopped working

Post by *Dalai »

sidefx88 wrote: 2020-06-13, 16:50 UTCI'm counting the brackets for the 10th time and that seems to be OK: (( ) ( ) ( )) (( ) ( ))
Sorry, I thought the "pause" was also enclosed on brackets like the rest, but it's not. So the syntax is correct.
Sorry, but I didn't understand when you said "Try echoing out every variable" and "add a question mark as the first parameter of the TC button".
See Stefan2's example.

BTW: That's one reason why I don't like putting full command lines in a TC button. Very difficult to debug. If in doubt, use a CMD script instead. That can be run without TC, e.g. on a CMD prompt.

Regards
Dalai
#101164 Personal licence
Ryzen 5 2600, 16 GiB RAM, ASUS Prime X370-A, Win7 x64

Plugins: Services2, Startups, CertificateInfo, SignatureInfo, LineBreakInfo - Download-Mirror
User avatar
sidefx88
Senior Member
Senior Member
Posts: 294
Joined: 2007-04-11, 17:07 UTC
Location: Argentina

Re: User command stopped working

Post by *sidefx88 »

2Dalai: yes, I agree with you about using one single line command, but will it work a CMD script for this?

The idea is to just select two files and then press a keyboard shortcut.

I thought (maybe I'm right, maybe I'm wrong) that using this single line command is what got this working (well, it is not working right now, but it did hehe)
I Love Total Commander!
User avatar
Stefan2
Power Member
Power Member
Posts: 4132
Joined: 2007-09-13, 22:20 UTC
Location: Europa

Re: User command stopped working

Post by *Stefan2 »

On win 10 I get an different quoting :

if "%p%s"=="%c1 %c2"

Code: Select all

if 
"F:\1\LUMINT~1\FISKAR~1.PNG" "F:\1\LUMINT~1\PARTYG~1.PNG"==
"F:\1\LUMINT~1\FISKAR~1.PNG F:\1\LUMINT~1\PARTYG~1.PNG" (


As show above, on w7 it looks like this:

if "%p%s"=="%c1 %c2"

Code: Select all

if 
"D:\d\5b\ACTIVE~1.EXE D:\d\5b\FOTOFR~1.PNG"==
"D:\d\5b\ACTIVE~1.EXE D:\d\5b\FOTOFR~1.PNG" (


- - -



Here it helps to add better quoting our self on w10:

if "%p%s"=="%c1" "%c2"

Code: Select all

if 
"F:\1\LUMINT~1\FISKAR~1.PNG" "F:\1\LUMINT~1\PARTYG~1.PNG"==
"F:\1\LUMINT~1\FISKAR~1.PNG" "F:\1\LUMINT~1\PARTYG~1.PNG" (
(the quoting would be ok that way too, or better to say, not need at all, as they are short 8.3 filenames,
but the '==' -comparison of the two strings fails, as they differ)




But that isn't it allow, there is something else different with that command between w7 and w10 :-(

 
User avatar
sidefx88
Senior Member
Senior Member
Posts: 294
Joined: 2007-04-11, 17:07 UTC
Location: Argentina

Re: User command stopped working

Post by *sidefx88 »

2Stefan2

Thanks for help.

So, something was changed on how cmd commands work on Win10.

That perfectly explains why the same script worked fine in Win7 :(
I Love Total Commander!
User avatar
Dalai
Power Member
Power Member
Posts: 9364
Joined: 2005-01-28, 22:17 UTC
Location: Meiningen (Südthüringen)

Re: User command stopped working

Post by *Dalai »

sidefx88 wrote: 2020-06-13, 17:56 UTC2Dalai: yes, I agree with you about using one single line command, but will it work a CMD script for this?
Why wouldn't it? The script will look quite different, of course. E.g.

Code: Select all

@echo off

if "%~2"=="" (
    echo You must select two files!
    echo.
    pause
    goto :EOF
)

move "%~1" "%~1.tempfile"
move "%~2" "%~1"
move "%~1.tempfile" "%~2"
TC user command

Code: Select all

[em_swapfilenames]
button=
cmd=cmd.exe /C
param="D:\path\swapfilenames.cmd" "%C1" "%C2"
BTW: I strongly recommend quoting (the uppercase) %C1 and %C2, even in your button, because that will break as soon as spaces or brackets in filenames are involved (only the lowercase %c1/%c2 will be 8.3).

BTW2: With such a script it's really easy to determine if it's TC's fault or that of Windows. Just run the script in a CMD prompt and then run it from a TC button and compare the results.

Regards
Dalai
#101164 Personal licence
Ryzen 5 2600, 16 GiB RAM, ASUS Prime X370-A, Win7 x64

Plugins: Services2, Startups, CertificateInfo, SignatureInfo, LineBreakInfo - Download-Mirror
User avatar
sidefx88
Senior Member
Senior Member
Posts: 294
Joined: 2007-04-11, 17:07 UTC
Location: Argentina

Re: User command stopped working

Post by *sidefx88 »

2Dalai:

Thanks a lot for this alternative script!

I've implemented it on TC, but... it doesn't work. So, I've changed the "cmd.exe /C" for "cmd.exe /K" to see an error message on the console.
The error is "System cannot find the path specified."

If I try the script outside TC, just running it on the console:

swapfilenames.cmd a.doc b.doc

This way it works perfect.

So, now the problem seems to be on TC, not on Windows cmd console.
I double checked the keyboard shortcut assignment (on wincmd.ini) and the user command (on usercmd.ini) and they're OK!

:(
I Love Total Commander!
User avatar
sidefx88
Senior Member
Senior Member
Posts: 294
Joined: 2007-04-11, 17:07 UTC
Location: Argentina

Re: User command stopped working

Post by *sidefx88 »

I guess the problem is on the usercmd.ini:

When I define "[em_swapfilenames]" command I use a relative TC path that Windows can't handle :(

[em_swapfilenames]
button=
cmd=cmd.exe /k
param="%COMMANDER_PATH%\swapfilenames.cmd" "%C1" "%C2"

I use a relative path because I sometimes use TC on a local hard disk, but sometimes as a portable app on flash drives :(

Is there a workaround for this or simply I must use an absolute path?
I Love Total Commander!
Post Reply