This shold do it:
Code: Select all
TOTALCMD#BAR#DATA
%COMSPEC% /C
if "%p%s"=="%c1 %c2" ((move %C1 %c1.tempfile) && (move %C2 %C1) && (move %c1.tempfile %C2)) else ((echo MARK TWO FILES!) && (echo.) && pause)
wcmicons.dll
Swap Two Filenames
-1
Moderators: white, Hacker, petermad, Stefan2
Code: Select all
TOTALCMD#BAR#DATA
%COMSPEC% /C
if "%p%s"=="%c1 %c2" ((move %C1 %c1.tempfile) && (move %C2 %C1) && (move %c1.tempfile %C2)) else ((echo MARK TWO FILES!) && (echo.) && pause)
wcmicons.dll
Swap Two Filenames
-1
Well, of course it can. That's why it's best to always quote variables when using them, you're even using a space yourself by writing "%c1 %c2". The issue is the quotes in the comparison. They are not always there but only when there are spaces in the path.petermad wrote:[...] since DOS' string comparison cannot handle spaces.
Code: Select all
@echo off
if "%~2"=="" goto ERR
if NOT "%~3"=="" goto ERR
move "%~1" "%~1.tempfile" && move "%~2" "%~1" && move "%~1.tempfile" "%~2"
pause
goto :EOF
:ERR
echo MARK TWO FILES!
echo.
pause
Code: Select all
TOTALCMD#BAR#DATA
%COMMANDER_PATH%\scripts\swapnames.cmd
?%P%S
wcmicons.dll
Swap Two Filenames
-1
Code: Select all
if "%p%s"=="%c1 %c2" ((move %C1 %c1.tempfile) && (move %C2 %C1) && (move %c1.tempfile %C2)) else ((echo MARK TWO FILES!) && (echo.) && pause)
Code: Select all
If ""c:\dir name\file name.txt" "c:\dir name\file name 2.txt""==""c:\dir name\file name.txt" "c:\dir name\file name 2.txt""
It is not an error it is just a way to have the command line displayed before it is executed. I used it when testing and forgot to remove it before I copied it.I removed the first "?" because I get an error. Is it right?)
It will not work since %C1 and %C2 are never ="" hence "%~1" is never =""if "%~1"=="" goto ERR
if NOT "%~3"=="" goto ERR
I think that extremely few users has done that...Short file names are not always available either, since they can be disabled on NTFS.
Code: Select all
TOTALCMD#BAR#DATA
%COMMANDER_PATH%\scripts\swapnames.cmd
%P%S %C1 %C2
wcmicons.dll
Swap Two Filenames
-1
Code: Select all
@echo off
if not "%~1 %~2"=="%~3 %~4" goto ERR
move "%~3" "%~3.tempfile" && move "%~4" "%~3" && move "%~3.tempfile" "%~4"
goto :EOF
:ERR
echo MARK TWO FILES!
echo.
pause
Well, the script may be used independently from TC, so it's always a good thing to prevent errors from happening.It will not work since %C1 and %C2 are never ="" hence "%~1" is never =""
Yep, you're right about that. It seems it's better to just use %P%S, and then even the check for the number of parameters makes sense again. And there's a little error in the first check. I'll update my post above.So: if "%~1"=="" will never trigger an error, and if no files are selected in TC your script will swap the file under the cursor with a file with the same name in the opposite panel if such file exists - not really what you want.
Note that %P%S is also never = "" If nothing is selected it returns the name of the file under the cursor...It seems it's better to just use %P%S
I have now added check for folder selection:Technically you'd need add a check whether the parameters are directories instead of file
Code: Select all
TOTALCMD#BAR#DATA
%COMSPEC% /C
if not "%p%s"=="%c1 %c2" ((echo MARK TWO FILES!) && (echo.) && pause) else if exist %c1\* ((echo DO NOT MARK DIRECTORIES!) && (echo.) && pause) else (move %C1 %c1.tempfile && move %C2 %C1 && move %c1.tempfile %C2)
wcmicons.dll
Swap Two Filenames
-1
I have been developing this button on a Windows 7 computer. After checking on my Windows 8.1 and Windows 10 machines, I see that short filenames (8dot3name) on NTFS volumes its by default only enabled for the system volume (drive C:).Quote:
Short file names are not always available either, since they can be disabled on NTFS.
I think that extremely few users has done that...