Swap the name of two files. Any method?
Moderators: Hacker, petermad, Stefan2, white
Swap the name of two files. Any method?
Hi!
There's a situation that happens to me often. I rename two files, but if I'm not very focused, sometimes I name the files switched, for example:
Fasc17_P01-03_03.jpg
Fasc17_P01-03_04.jpg
This names are swithed by mistake, so I have to rename them again.
Fasc17_P01-03_03.jpg
Fasc17_P01-03_04a.jpg
Then...
Fasc17_P01-03_04.jpg
Fasc17_P01-03_04a.jpg
And then...
Fasc17_P01-03_04.jpg
Fasc17_P01-03_03.jpg
Is there a way (command, chain of commands, CMD/BAT script) to just select this two files and press a button (or even better: a hotkey) to do the filename swap automatically?
Thanks in advance!
There's a situation that happens to me often. I rename two files, but if I'm not very focused, sometimes I name the files switched, for example:
Fasc17_P01-03_03.jpg
Fasc17_P01-03_04.jpg
This names are swithed by mistake, so I have to rename them again.
Fasc17_P01-03_03.jpg
Fasc17_P01-03_04a.jpg
Then...
Fasc17_P01-03_04.jpg
Fasc17_P01-03_04a.jpg
And then...
Fasc17_P01-03_04.jpg
Fasc17_P01-03_03.jpg
Is there a way (command, chain of commands, CMD/BAT script) to just select this two files and press a button (or even better: a hotkey) to do the filename swap automatically?
Thanks in advance!
I Love Total Commander!
Something like:
swap_names.cmd
button:
Change paths and names to your taste
swap_names.cmd
Code: Select all
@echo off
ren %1 _$$$qqq.qqq$$_
ren %2 %1
ren _$$$qqq.qqq$$_ %2
Code: Select all
TOTALCMD#BAR#DATA
swap_names.cmd
%S
WCMICONS.DLL,80
swap_names
1
-1
It's impossible to lead us astray for we don't care even to choose the way.
#259941, TC 11.01 x64, Windows 7 SP1 x64
#259941, TC 11.01 x64, Windows 7 SP1 x64
2sidefx88
You can make a userdefined command like this:Copy the code above to your usercmd.ini file
You can then make a userdefined hotkey for the em_swapfilenames command.
And / or you can make a button with this content:Copy the code above and right click on the button bar to paste the button.
If you ONLY want a button you can use this:Copy the code above and right click on the button bar to paste the button.
This approach ensures that two and only two files are selected before running the commands and gives you a message if not.
You can make a userdefined command like this:
Code: Select all
[em_swapfilenames]
button=wcmicons.dll,0
cmd=%COMSPEC% /C
menu=Swap Two Filenames
param=if "%P%S"=="%C1 %C2" ((move %C1 %Ptempfile) && (move %C2 %C1) && (move %Ptempfile %C2)) else ((echo MARK TWO FILES!) && (echo.) && pause)
You can then make a userdefined hotkey for the em_swapfilenames command.
And / or you can make a button with this content:
Code: Select all
TOTALCMD#BAR#DATA
em_swapfilenames
wcmicons.dll
Swap Two Filenames
0
10365
If you ONLY want a button you can use this:
Code: Select all
TOTALCMD#BAR#DATA
%COMSPEC% /C
if "%P%S"=="%C1 %C2" ((move %C1 %Ptempfile) && (move %C2 %C1) && (move %Ptempfile %C2)) else ((echo MARK TWO FILES!) && (echo.) && pause)
wcmicons.dll,0
Swap Two Filenames
-1
This approach ensures that two and only two files are selected before running the commands and gives you a message if not.
License #524 (1994)
Danish Total Commander Translator
TC 11.55rc4 32+64bit on Win XP 32bit & Win 7, 8.1 & 10 (22H2) 64bit, 'Everything' 1.5.0.1393a
TC 3.60b4 on Android 6, 13, 14
TC Extended Menus | TC Languagebar | TC Dark Help | PHSM-Calendar
Danish Total Commander Translator
TC 11.55rc4 32+64bit on Win XP 32bit & Win 7, 8.1 & 10 (22H2) 64bit, 'Everything' 1.5.0.1393a
TC 3.60b4 on Android 6, 13, 14
TC Extended Menus | TC Languagebar | TC Dark Help | PHSM-Calendar
This is a very elegant solution Peter, to be safer, you could use %C1.tempfile istead of %PTempfile just to prevent collision or have a easiest way to go back if the second move fail..petermad wrote:2sidefx88
You can make a userdefined command like this:Copy the code above to your usercmd.ini fileCode: Select all
[em_swapfilenames] button=wcmicons.dll,0 cmd=%COMSPEC% /C menu=Swap Two Filenames param=if "%P%S"=="%C1 %C2" ((move %C1 %Ptempfile) && (move %C2 %C1) && (move %Ptempfile %C2)) else ((echo MARK TWO FILES!) && (echo.) && pause)
You can then make a userdefined hotkey for the em_swapfilenames command.
And / or you can make a button with this content:Copy the code above and right click on the button bar to paste the button.Code: Select all
TOTALCMD#BAR#DATA em_swapfilenames wcmicons.dll Swap Two Filenames 0 10365
If you ONLY want a button you can use this:Copy the code above and right click on the button bar to paste the button.Code: Select all
TOTALCMD#BAR#DATA %COMSPEC% /C if "%P%S"=="%C1 %C2" ((move %C1 %Ptempfile) && (move %C2 %C1) && (move %Ptempfile %C2)) else ((echo MARK TWO FILES!) && (echo.) && pause) wcmicons.dll,0 Swap Two Filenames -1
This approach ensures that two and only two files are selected before running the commands and gives you a message if not.
Good idea!you could use %C1.tempfile istead of %PTempfile
Here is the updated code:
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
Code: Select all
[em_swapfilenames]
button=wcmicons.dll
cmd=%COMSPEC% /C
menu=Swap Two Filenames
param=if "%P%S"=="%C1 %C2" ((move %C1 %C1.tempfile) && (move %C2 %C1) && (move %C1.tempfile %C2)) else ((echo MARK TWO FILES!) && (echo.) && pause)
License #524 (1994)
Danish Total Commander Translator
TC 11.55rc4 32+64bit on Win XP 32bit & Win 7, 8.1 & 10 (22H2) 64bit, 'Everything' 1.5.0.1393a
TC 3.60b4 on Android 6, 13, 14
TC Extended Menus | TC Languagebar | TC Dark Help | PHSM-Calendar
Danish Total Commander Translator
TC 11.55rc4 32+64bit on Win XP 32bit & Win 7, 8.1 & 10 (22H2) 64bit, 'Everything' 1.5.0.1393a
TC 3.60b4 on Android 6, 13, 14
TC Extended Menus | TC Languagebar | TC Dark Help | PHSM-Calendar
Hi guys! Thanks for answering, but it doesn't work here.
Maybe I'm doing it in the wrong way...
I decided to use a hotkey only (no button on bar needed).
I assign Ctrl+Shift+R to command 'em_swapfilenames'.
And I defined the command on usercmd.ini:
cmd=%COMSPEC% /C
param=if "%P%S"=="%C1 %C2" ((move %C1 %C1.tempfile) && (move %C2 %C1) && (move %C1.tempfile %C2)) else ((echo MARK TWO FILES!) && (echo.) && pause)
When I select two files (same panel) and then press Ctrl+Shift+R a console window pops up, showing "MARK TWO FILES!" message, and below: "Press any key to continue..."
And the file(name)s stay the same.
Any idea on what's wrong?
Maybe I'm doing it in the wrong way...
I decided to use a hotkey only (no button on bar needed).
I assign Ctrl+Shift+R to command 'em_swapfilenames'.
And I defined the command on usercmd.ini:
cmd=%COMSPEC% /C
param=if "%P%S"=="%C1 %C2" ((move %C1 %C1.tempfile) && (move %C2 %C1) && (move %C1.tempfile %C2)) else ((echo MARK TWO FILES!) && (echo.) && pause)
When I select two files (same panel) and then press Ctrl+Shift+R a console window pops up, showing "MARK TWO FILES!" message, and below: "Press any key to continue..."
And the file(name)s stay the same.
Any idea on what's wrong?
Last edited by sidefx88 on 2016-07-26, 15:55 UTC, edited 1 time in total.
I Love Total Commander!
Are you sure the line:
is in one line...
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)
License #524 (1994)
Danish Total Commander Translator
TC 11.55rc4 32+64bit on Win XP 32bit & Win 7, 8.1 & 10 (22H2) 64bit, 'Everything' 1.5.0.1393a
TC 3.60b4 on Android 6, 13, 14
TC Extended Menus | TC Languagebar | TC Dark Help | PHSM-Calendar
Danish Total Commander Translator
TC 11.55rc4 32+64bit on Win XP 32bit & Win 7, 8.1 & 10 (22H2) 64bit, 'Everything' 1.5.0.1393a
TC 3.60b4 on Android 6, 13, 14
TC Extended Menus | TC Languagebar | TC Dark Help | PHSM-Calendar
I guess, the file names (%C1 and %C2 variables) must be quoted to make the command work for paths with spaces.
Regards
Dalai
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
Ryzen 5 2600, 16 GiB RAM, ASUS Prime X370-A, Win7 x64
Plugins: Services2, Startups, CertificateInfo, SignatureInfo, LineBreakInfo - Download-Mirror
For those where it doesn't work:
%C1 and %C2 needs minimum TC9.0 beta 1 or newer.
TC9 beta6 >> http://ghisler.ch/board/viewtopic.php?t=44960
%C1 and %C2 needs minimum TC9.0 beta 1 or newer.
TC9 beta6 >> http://ghisler.ch/board/viewtopic.php?t=44960
08.06.16 Release Total Commander 9.0 beta 1 (32/64)
19.01.16 Added: Button bar, start menu parameters %C3..%C9: Selected files Nr. 3..9, empty if not as many selected (32/64)
19.01.16 Added: Button bar, start menu parameters %c1, %c2: Same as %C1, %C2, but with alternate 8.3 paths and names (DOS names) (32/64)
19.01.16 Added: Button bar, start menu parameters %C1, %C2: Compare parameters as in "Compare by content": First two selected files (with full path), or selected in source+target panel, or source file+same name in target panel (32/64)