Copy with suffix - like multi-rename

English support forum

Moderators: white, Hacker, petermad, Stefan2

Post Reply
kodepr
Junior Member
Junior Member
Posts: 38
Joined: 2019-09-05, 08:13 UTC

Copy with suffix - like multi-rename

Post by *kodepr »

Hi,

I want to periodically create a backup of a specific file.
This Multi-Rename mask does exactly what I want ...

Code: Select all

[N]_Backup [=tc.writedate.Y-M-D]_[=tc.writetime.h]h[=tc.writetime.m]-[=tc.writetime.s]
... except it doesn't create a copy. So for now I have to copy the file first, and then use the Rename mask.

I would like to have one operation that does both the copy and the naming part, but I don't know how. Is it possible?

In a perfect world, it would be one button on the toolbar that does everything in the background, without having to navigate to the folder, select the file, etc. ...

Thanks in advance!
User avatar
Stefan2
Power Member
Power Member
Posts: 4159
Joined: 2007-09-13, 22:20 UTC
Location: Europa

PowerShell: Copy with "WriteTime"-suffix to backup - like multi-rename

Post by *Stefan2 »

 

You can always use the script language of your OS:


FROM:
TOTALCMD.EXE 5.758.272 21.02.2024 11:03 -a--

TO:
TOTALCMD.EXE 5.758.272 21.02.2024 11:03 -a--
TOTALCMD_Backup_2024-02-21-110300.EXE 5.758.272 21.02.2024 11:03 -a--

USE:
'%N'| ForEach-Object{$Obj=(GET-ITEM $_);COPY-ITEM $_ $($Obj.BaseName + $Obj.LastWriteTime.ToString('_Backup_yyyy-MM-dd-HHmmss') + $Obj.Extension)}



Note: %N is an TC internal parameter.



This as button:
Command: PowerShell -NoExit
Parameters: '%N'| %%{$O=(GI $_);COPY $_ $($O.BaseName + $O.LastWriteTime.ToString('_Backup_yyyy-MM-dd-HHmmss') + $O.Extension)}
Start path:
C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.exe
Icon: 0
Tooltip: Copy current file in current folder and add LastWriteTime-timestamp


Ready to use copy&paste button:

Code: Select all

TOTALCMD#BAR#DATA
PowerShell -NoExit
'%N'| %%{$O=(GI $_);COPY $_ $($O.BaseName + $O.LastWriteTime.ToString('_Backup_yyyy-MM-dd-HHmmss') + $O.Extension)}
C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.exe
Copy current file in current folder and add LastWriteTime-timestamp

1



see my sig for more...
 
kodepr
Junior Member
Junior Member
Posts: 38
Joined: 2019-09-05, 08:13 UTC

Re: Copy with suffix - like multi-rename

Post by *kodepr »

Thanks a lot Stefan2,

I don't understand any of the script language, but I pasted the TOTALCMD#BAR#DATA on my TC-toolbar and it does the job!

Just FYI, I changed it a bit afterwards to:
TOTALCMD#BAR#DATA
PowerShell -NoExit
'%S'| %%{$O=(GI $_);COPY $_ $($O.BaseName + $O.LastWriteTime.ToString('_Backup_yyyy-MM-dd-HHmmss') + $O.Extension)}
C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.exe
Copy selected file in current folder and add LastWriteTime-timestamp

1


red = I deleted that because I prefer the powershell window not to stay open after a copy.
green = I changed that because I'm not sure how to use "file under cursor" (%N) - if I put my cursor over the correct file first and then move my cursor to the toolbar button, the correct file is no longer under the cursor (?)
User avatar
Stefan2
Power Member
Power Member
Posts: 4159
Joined: 2007-09-13, 22:20 UTC
Location: Europa

Re: Copy with suffix - like multi-rename

Post by *Stefan2 »

Fine, glad it works for you.

red > that's pretty fine for real work, 'no close' is only for debuggin purpose, to see the possible error.
green > '%N' works for me, as I click on the file to 'select' it, and next on the button,...... but no problem, there are a few ways to achieve the goal.





pro tip:

you can adjust the code just slightly to work on one-or-many selected files the same time:

-----------------------------------
TOTALCMD#BAR#DATA
powershell -NoExit
GC '%F'| %%{$_ ; $O=(GI $_);COPY $_ $($O.BaseName + $O.LastWriteTime.ToString('_Backup_yyyy-MM-dd-HHmmss') + $O.Extension)}
C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.exe
Copy all selected files to a backup file AND add '_Backup_' with last writedate to the filename.

1
-1
-----------------------------------





GC ==> Get-Content        (like the DOS "TYPE"-command)
GI ==> Get-Item
%F is a TC internal parameter

 
kodepr
Junior Member
Junior Member
Posts: 38
Joined: 2019-09-05, 08:13 UTC

Re: Copy with suffix - like multi-rename

Post by *kodepr »

Hi Stefan2,

red > aha, I see
green > I had "Open files and diretories with a single click" enabled in the options - turned off, %N works great
pro tip > wonderful!

While playing around with your first TOTALCMD#BAR#DATA I noticed that if I change %N to the path of the correct file, like
TOTALCMD#BAR#DATA
PowerShell
'c:\testfile.txt'| %%{$O=(GI $_);COPY $_ $($O.BaseName + $O.LastWriteTime.ToString('_Backup_yyyy-MM-dd-HHmmss') + $O.Extension)}
C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.exe,1
Copy testfile and add LastWriteTime-timestamp


1
-1

I can run the command while I'm in another source path (like E:\backup files\) and it will copy c:\testfile.txt to "E:\backup files\" with the suffix, so I can have my backups created in another path than the original file.

Very useful, thanks!
I'm currently using Total Commander Version 10.00 64bit
User avatar
Stefan2
Power Member
Power Member
Posts: 4159
Joined: 2007-09-13, 22:20 UTC
Location: Europa

Re: Copy with suffix - like multi-rename

Post by *Stefan2 »

kodepr wrote: 2024-04-15, 09:51 UTC
so I can have my backups created in another path than the original file.

Bravo!



Yes, with TCs' parameter and a scripting languages you can do many things on your own.

For example lookup the TC-parameter %T

Click the [Help]-Button or press the F1-key or open the TOTALCMD.CHM from TC folder (or subfolder "e").
In CHM go > Operation > User interface > click on the "Button bar"-picture > in the text click on "Dialog box to change"
> use then there the "Ctrl+F"-search to find %T

%T    inserts the current TARGET path.




-----------------------------------
TOTALCMD#BAR#DATA
powershell -NoExit
GC '%F'| %%{$_ ; $O=(GI $_);COPY $_ $( '%T' + $O.BaseName + $O.LastWriteTime.ToString('_Backup_yyyy-MM-dd-HHmmss') + $O.Extension)}
C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.exe
Copy ALL selected files to TARGET as a backup AND add last writedate to the filename.

1
-1
-----------------------------------






You can also put a leading question mark-sign as FIRST parameter, for to be prompted, to check and maybe adjust the command:
Parameters: ?'%N'| %%{$O=(GI $ . . . . . . .



 
User avatar
Hacker
Moderator
Moderator
Posts: 13068
Joined: 2003-02-06, 14:56 UTC
Location: Bratislava, Slovakia

Re: Copy with suffix - like multi-rename

Post by *Hacker »

kodepr,
I had "Open files and diretories with a single click" enabled
You can also hold Ctrl while moving the mouse, then the highlighted file does not change.

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.
Post Reply