Rename file on right panel the same as file on left panel + prefix/suffix

English support forum

Moderators: white, Hacker, petermad, Stefan2

mlc4886
Junior Member
Junior Member
Posts: 3
Joined: 2023-05-14, 14:27 UTC

Rename file on right panel the same as file on left panel + prefix/suffix

Post by *mlc4886 »

Good afternoon,

I am currently trying to work out if it's possible to rename a file on the right panel the same as the file on the left panel plus a specific suffix/prefix? i.e. left file (source document) is called Test Document.docx and the right file (target document being returned to me) is called Test+Document-LP.docx

The documents should have the same name, but following the file being returned to me from someone else, it often has a slightly different naming convention. The fastest way I have worked out is the follow:

Select left file
ALT+C (redefined hotkey for rename single file)
CTRL +C (Copy)
Select right file
ALT+C (redefined hotkey for rename single file)
CTRL+V (Paste)

I tried creating a new command even for just renaming and copying, and a second for renaming and pasting by editing the usercmd.ini file with an em_Command, however this didn't seem to work.

If anybody has an idea on how to achieve this so by selecting a file in the source and a file in the target I could rename them the same with one click (and a suffix/prefix if possible) then I would be greatful!
Matthew
User avatar
Hacker
Moderator
Moderator
Posts: 13052
Joined: 2003-02-06, 14:56 UTC
Location: Bratislava, Slovakia

Re: Rename file on right panel the same as file on left panel + prefix/suffix

Post by *Hacker »

all,
Does anyone know if there is a %O but for the target file? Then we could do something like

Code: Select all

cmd /c ren %N "%???.%E"
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
petermad
Power Member
Power Member
Posts: 14743
Joined: 2003-02-05, 20:24 UTC
Location: Denmark
Contact:

Re: Rename file on right panel the same as file on left panel + prefix/suffix

Post by *petermad »

Hacker wrote: 2023-05-14, 15:09 UTC all,
Does anyone know if there is a %O but for the target file? Then we could do something like

Code: Select all

cmd /c ren %N "%???.%E"
You could use %M:~-0,255 to get the file name without extension of the file under the cursor in the target panel.
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
Hacker
Moderator
Moderator
Posts: 13052
Joined: 2003-02-06, 14:56 UTC
Location: Bratislava, Slovakia

Re: Rename file on right panel the same as file on left panel + prefix/suffix

Post by *Hacker »

petermad,
use %M:~-0,255
Thanks! Would be nice if that was documented in the Help file :roll:

mlc4886,

Code: Select all

Command: cmd
Parameters: /k ren %N "%M:~-0,255.%E"
Seems to work. You can either add it to a button bar, or configure a hotkey, and create a new usercmd.ini em_ type command using the above details. You can also add any prefix or suffix if you like, e.g. "MyPrefix%M:~-0,255.%E" or "%M:~-0,255MySuffix.%E".

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
petermad
Power Member
Power Member
Posts: 14743
Joined: 2003-02-05, 20:24 UTC
Location: Denmark
Contact:

Re: Rename file on right panel the same as file on left panel + prefix/suffix

Post by *petermad »

Thanks! Would be nice if that was documented in the Help file
I somewhat is:
Help wrote:Note: All parameters now support substring fields in the form :~start,length, e.g. %N:~2,5 or %N:~-8,5 . To append a number directly after the length value, use another ~ character, e.g. %N:~2,5~2. Negative vaules are measured from the end of the string. Example: %P:~0,-1 cuts off the backslash from the path.
The Start value -0 is special: %N:~-0,20 copies the first 20 characters of the name without extension, %N:~-0,-20 the first 20 characters of the extension without the name.
I just changed 20 to 255
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
Hacker
Moderator
Moderator
Posts: 13052
Joined: 2003-02-06, 14:56 UTC
Location: Bratislava, Slovakia

Re: Rename file on right panel the same as file on left panel + prefix/suffix

Post by *Hacker »

petermad,
Darn, must read more carefully. Thanks.

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.
mlc4886
Junior Member
Junior Member
Posts: 3
Joined: 2023-05-14, 14:27 UTC

Re: Rename file on right panel the same as file on left panel + prefix/suffix

Post by *mlc4886 »

This is great and exactly what I was trying to create, thanks!

I've given it a go on two computers and I keep getting a 'The system cannot find the file specified' error through the cmd prompt. I'll try and fix that then report back on my end.

Thanks!
Matthew
User avatar
Hacker
Moderator
Moderator
Posts: 13052
Joined: 2003-02-06, 14:56 UTC
Location: Bratislava, Slovakia

Re: Rename file on right panel the same as file on left panel + prefix/suffix

Post by *Hacker »

mlc4886,
Perhaps you didn't clear the Start path in the button you made.

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
petermad
Power Member
Power Member
Posts: 14743
Joined: 2003-02-05, 20:24 UTC
Location: Denmark
Contact:

Re: Rename file on right panel the same as file on left panel + prefix/suffix

Post by *petermad »

2mlc4886
You could try replacing cmd with %COMSPEC%
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
Hacker
Moderator
Moderator
Posts: 13052
Joined: 2003-02-06, 14:56 UTC
Location: Bratislava, Slovakia

Re: Rename file on right panel the same as file on left panel + prefix/suffix

Post by *Hacker »

petermad,
Well, if that was the problem, he wouldn't get the cmd prompt.

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
petermad
Power Member
Power Member
Posts: 14743
Joined: 2003-02-05, 20:24 UTC
Location: Denmark
Contact:

Re: Rename file on right panel the same as file on left panel + prefix/suffix

Post by *petermad »

Well, if that was the problem, he wouldn't get the cmd prompt.
So that is what " through the cmd prompt." meant - sorry.

Then I guess we have to use full paths:

Code: Select all

Parameters: /k ren %P%N "%T%M:~-0,255.%E"
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
Hacker
Moderator
Moderator
Posts: 13052
Joined: 2003-02-06, 14:56 UTC
Location: Bratislava, Slovakia

Re: Rename file on right panel the same as file on left panel + prefix/suffix

Post by *Hacker »

petermad,
I don't think that's necessary if the Start path is cleared.

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
petermad
Power Member
Power Member
Posts: 14743
Joined: 2003-02-05, 20:24 UTC
Location: Denmark
Contact:

Re: Rename file on right panel the same as file on left panel + prefix/suffix

Post by *petermad »

Hacker wrote: 2023-05-15, 12:20 UTC petermad,
I don't think that's necessary if the Start path is cleared.
You are right. And my suggestion doesn't work because the new filename cannot have a path.

But this:

Code: Select all

Command: %COMSPEC%
Parameters: /k ren %P%N "%M:~-0,255.%E"
Will work even if the Start path is not empty and independent on which command interpreter you use (cmd.exe, command.com or third party)
Last edited by petermad on 2023-05-15, 13:28 UTC, edited 1 time in total.
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
Hacker
Moderator
Moderator
Posts: 13052
Joined: 2003-02-06, 14:56 UTC
Location: Bratislava, Slovakia

Re: Rename file on right panel the same as file on left panel + prefix/suffix

Post by *Hacker »

petermad,
&COMSPEC%
What does the & do? Or is that a typo?

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
petermad
Power Member
Power Member
Posts: 14743
Joined: 2003-02-05, 20:24 UTC
Location: Denmark
Contact:

Re: Rename file on right panel the same as file on left panel + prefix/suffix

Post by *petermad »

What does the & do? Or is that a typo?
Sorry - it was a typo - corrected now.
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
Post Reply