User command stopped working

English support forum

Moderators: sheep, Hacker, Stefan2, white

User avatar
Dalai
Power Member
Power Member
Posts: 7118
Joined: 2005-01-28, 22:17 UTC
Location: Meiningen (Südthüringen)

Re: User command stopped working

Post by *Dalai »

Sorry, didn't test it properly. The %C1/%C2 parameters are quoted by TC automatically. When you remove the quotes around them it should work.

However, there's a catch: When only one file is selected, TC puts that in the command line twice. This is documented in TC's help, but you should definitely keep that in mind! It's probably safer to use %P%S2 instead of %C1 %C2.

Updated script to catch two identical files selected:

Code: Select all

@echo off

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

if "%~1"=="%~2" (
    echo Two identical files selected!
    echo.
    pause
    goto :EOF
)

move "%~1" "%~1.tempfile"
move "%~2" "%~1"
move "%~1.tempfile" "%~2"
Regards
Dalai
#101164 Personal licence
Ryzen 5 2600, 16 GiB RAM, ASUS Prime X370-A, Win7 x64

Plugins: Services2, Startups

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

Re: User command stopped working

Post by *sidefx88 »

2Dalai:

Thanks a lot!

It works perfectly now :)
I Love Total Commander!

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

Re: User command stopped working

Post by *sidefx88 »

But only works if swapfilenames.cmd is refered with an absolute path on usercmd.ini or if it has no path at all (just filename and extension) and I put that cmd file on a folder that is included on the path variable, for example: Windows.

:/
I Love Total Commander!

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

Re: User command stopped working

Post by *sidefx88 »

And the last little problem is if I accidentaly press the keyborad shortcut for swaping filenames with NO selected files:

The file under the cursor will be moved to the other panel :O
I Love Total Commander!

User avatar
Dalai
Power Member
Power Member
Posts: 7118
Joined: 2005-01-28, 22:17 UTC
Location: Meiningen (Südthüringen)

Re: User command stopped working

Post by *Dalai »

sidefx88 wrote:
2020-06-14, 14:04 UTC
But only works if swapfilenames.cmd is refered with an absolute path on usercmd.ini [...]
How exactly did you specify the path to the script? It should definitely work with environment variables.
sidefx88 wrote:
2020-06-14, 14:07 UTC
And the last little problem is if I accidentaly press the keyborad shortcut for swaping filenames with NO selected files:

The file under the cursor will be moved to the other panel :O
As I said: Replace %C1 %C2 by %P%S2 to avoid having TC repeat the filename of the first selected file, even with a path of the opposite panel. The script will take care of the rest (skipping when only one parameter is specified).

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

Plugins: Services2, Startups

User avatar
HolgerK
Power Member
Power Member
Posts: 5221
Joined: 2006-01-26, 22:15 UTC
Location: Europe, Aachen

Re: User command stopped working

Post by *HolgerK »

sidefx88 wrote:
2020-06-14, 02:27 UTC
[em_swapfilenames]
button=
cmd=cmd.exe /k
param="%COMMANDER_PATH%\swapfilenames.cmd" "%C1" "%C2"
This should be:

Code: Select all

cmd=cmd.exe /k "%COMMANDER_PATH%\swapfilenames.cmd" 
param="%C1" "%C2"
if TC should expand the environment variable.

Or:

Code: Select all

cmd=cmd.exe /k 
param="%%COMMANDER_PATH%%\swapfilenames.cmd"  "%C1" "%C2"
If cmd.exe can expand the environment variable.

Regards
Holger
Make our planet great again

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

Re: User command stopped working

Post by *sidefx88 »

2Dalai: you're right. I've replaced '"%C1" "%C2"' for '%P%S2'.

2HolgerK: it works (almost) perfect now using this combination:

usercmd.ini:

Code: Select all

[em_swapfilenames]
button=
cmd=cmd.exe /k "%COMMANDER_PATH%\swapfilenames.cmd"
param=%P%S2
But, it only works if both filenames have no spaces. If at least one space is in one filename (or in both) I get this error:

"C:\Total" is not recognized as an internal or external command,
operable program or batch file.

Maybe some "" are missing somewhere.
I Love Total Commander!

User avatar
Dalai
Power Member
Power Member
Posts: 7118
Joined: 2005-01-28, 22:17 UTC
Location: Meiningen (Südthüringen)

Re: User command stopped working

Post by *Dalai »

You should try without the "cmd.exe /k" - i.e. directly calling swapfilenames.cmd - because that switch (along with /c) require additional quoting in certain cases since they remove the first and last quote when some conditions are met, making this difficult to debug. If you need the CMD window to stay open, add a "pause" at the script's end.

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

Plugins: Services2, Startups

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

Re: User command stopped working

Post by *sidefx88 »

2Dalai: Great!

Thanks a lot. Now it is working 100% fine :)
I Love Total Commander!

User avatar
petermad
Power Member
Power Member
Posts: 9662
Joined: 2003-02-05, 20:24 UTC
Location: Valsted, Denmark
Contact:

Re: User command stopped working

Post by *petermad »

Here is the solution I use in my Extended menus - it still works under Windows 10, but Windows 10 doesn't give the beep at errors as Windows 7 does:

Code: Select all

[em_ext_swapfilenames]
cmd=%COMSPEC% /C
param=if not exist "%P" (echo •) else if exist %P%S1\ (echo •) else if not *%C3==* (echo •) else if %C2==%T%S1 (echo •) else if %C2==%P%S1 (echo •) else echo Temp file for TC Extended Menu > %%TEMP%%\tc_ext.tmp && xcopy %C1 %%TEMP%%\tc_ext.tmp /H /R /K /Y && xcopy %C2 %C1 /H /R /K /Y && xcopy %%TEMP%%\tc_ext.tmp %C2 /H /R /K /Y && del %%TEMP%%\tc_ext.tmp /F /A
menu=Swap the content of two files in same panel
button=wcmicons.dll
iconic=1

This doesn't use the move command, but the xcopy command - this way is also work for hidden and system files

It checks for:
Being on a drive that DOS recognizes (if not exist "%P")
Not having selected a folder (if exist %P%S1\)
Not having selected more than 2 files (if not *%C3==*)
Not having selected one file in active panel, and one in inactive panel (if %C2==%T%S1)
Not having selected only one file (if %C2==%P%S1)

The • is the Bell control character (Alt+Num 7)
License #524
Danish Total Commander Translator
TC 9.51 32+64bit on Win XP 32bit, Win 7, 8.1 & 10 (1909) 64bit, 'Everything' 1.4.1.965 (x64)
TC 3.0 on Android 6.0
Get:
Extended Total Commander Menus | TC Languagebar | TC Dark Help | PHSM-Calendar

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

Re: User command stopped working

Post by *sidefx88 »

Thanks, petermad!

I will try this method as well.

Regards
I Love Total Commander!

User avatar
petermad
Power Member
Power Member
Posts: 9662
Joined: 2003-02-05, 20:24 UTC
Location: Valsted, Denmark
Contact:

Re: User command stopped working

Post by *petermad »

I remember that I in one of my earlier solutions (extended Menus v. 9.00) I used lowercase c1 and c2 (exactly as your code in the first post), but I gave up using that - mostly because 8.3 names are only enabled by default on drive c: on newer OS'es. You have to manually enable it in the registry for other partitions under Windows 10.

BTW - we have been there before: viewtopic.php?p=313885#p313885
License #524
Danish Total Commander Translator
TC 9.51 32+64bit on Win XP 32bit, Win 7, 8.1 & 10 (1909) 64bit, 'Everything' 1.4.1.965 (x64)
TC 3.0 on Android 6.0
Get:
Extended Total Commander Menus | TC Languagebar | TC Dark Help | PHSM-Calendar

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

Re: User command stopped working

Post by *sidefx88 »

Thanks for the explanation.

Yes, I remember that thread on this forum. You were the guy who gave an elegant solution for this a few years ago (when I was using Windows 7), but -as I said before- it doesn't work anymore on Windows 10.

I will try your new code as well, definitely!

Thanks again :)
I Love Total Commander!

User avatar
Stefan2
Power Member
Power Member
Posts: 2923
Joined: 2007-09-13, 22:20 UTC
Location: Europa

Re: User command stopped working

Post by *Stefan2 »

petermad wrote:
2020-06-15, 11:01 UTC
by *petermad » Mon Jun 15, 2020 13:01
I tested your script out of curiosity.

Sorry, but that error check didn't work for me.
Microsoft Windows [Version 10.0.18363.900] - Eng/Ger


To check why, I have exchanged the "(echo •)"-parts by "(ECHO err)".

cmd /k
if not exist "%P" (ECHO errA) else if exist %P%S1\ (ECHO errB) else if not *%C3==* (ECHO errC) else if %C2==%T%S1 (ECHO errD) else if %C2==%P%S1 (ECHO errE) and the rest...


It stops for me at errB , but I have no sub folders in that test folder.



By removing all of that error checks the command works for me.

cmd /c
echo Temp file for TC Extended Menu > %%TEMP%%\tc_ext.tmp && xcopy %C1 %%TEMP%%\tc_ext.tmp /H /R /K /Y && xcopy %C2 %C1 /H /R /K /Y && xcopy %%TEMP%%\tc_ext.tmp %C2 /H /R /K /Y && del %%TEMP%%\tc_ext.tmp /F /A



- - -


Here is an alternative PoSh script for an All-in-one-button command:

Code: Select all

TOTALCMD#BAR#DATA
PowerShell
$C=Get-Content '%F';if($C.count -eq 2){Rename-Item $C[0] ($C[0]+'.tmp');Rename-Item $C[1] $C[0];Rename-Item ($C[0]+'.tmp') $C[1]}else{'Select TWO items from one panel'}
C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.exe
Swap names of TWO selected files

1
-1
(this is an copy&paste Button-code)


The script:
$C=Get-Content '%F';
if($C.count -eq 2){
Rename-Item $C[0] ($C[0]+'.tmp');
Rename-Item $C[1] $C[0];
Rename-Item ($C[0]+'.tmp') $C[1]
}else{'Select TWO items from one panel'}



Me think, that would be enough code for that script (it anyway just takes the first two files from the selection):
$C=Get-Content '%F';Rename-Item $C[0] ($C[0]+'tmp');Rename-Item $C[1] $C[0];Rename-Item ($C[0]+'tmp') $C[1];

For error checking use "PowerShell -NoExit" as cmd



 

User avatar
petermad
Power Member
Power Member
Posts: 9662
Joined: 2003-02-05, 20:24 UTC
Location: Valsted, Denmark
Contact:

Re: User command stopped working

Post by *petermad »

2Stefan2
Hmm, it works fine here on Windows 10...

Does it help if you change:
if exist %P%S1\ (echo errB)
with
if exist %P%S1\* (echo errB)

What are the names of the files you test with?

Could you please try this button on files and folders:

Code: Select all

TOTALCMD#BAR#DATA
%COMSPEC% /K
if exist %P%S1\ (echo FOLDER) else echo FILE
%COMMANDER_EXE%,2
Test for folder or file


-1
Last edited by petermad on 2020-06-16, 11:12 UTC, edited 1 time in total.
License #524
Danish Total Commander Translator
TC 9.51 32+64bit on Win XP 32bit, Win 7, 8.1 & 10 (1909) 64bit, 'Everything' 1.4.1.965 (x64)
TC 3.0 on Android 6.0
Get:
Extended Total Commander Menus | TC Languagebar | TC Dark Help | PHSM-Calendar

Post Reply