File Versioning - Create a serialized copy of a file

English support forum

Moderators: Hacker, petermad, Stefan2, white

Post Reply
risk
Junior Member
Junior Member
Posts: 87
Joined: 2007-07-30, 03:18 UTC

File Versioning - Create a serialized copy of a file

Post by *risk »

This is something I do manually and hopefully someone can help automate the process.

If I have a file named text.txt and I want to save a copy before editing it, I usually do a {Shift}{F5} and create a copy named text.0.txt

If I later want to create another backup copy, I do the same process and increment the number.

Is there a more automated way of doing this in TC or has anyone done something similar by scripting in AHK or batch file?

Thanks in advance.
User avatar
MVV
Power Member
Power Member
Posts: 8711
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Post by *MVV »

TC has no built-in function. But here a batch:

Code: Select all

@echo off
if -%1==- echo Parameters: %%P%%N & pause & goto :EOF
set counter=0
:next_name
set copy_name=%~dpn1.%counter%%~x1
set /a counter=%counter%+1
if exist "%copy_name%" goto next_name
copy %1 "%copy_name%"
User avatar
Hacker
Moderator
Moderator
Posts: 13144
Joined: 2003-02-06, 14:56 UTC
Location: Bratislava, Slovakia

Post by *Hacker »

risk,
Ctrl-C, Ctrl-V?

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.
risk
Junior Member
Junior Member
Posts: 87
Joined: 2007-07-30, 03:18 UTC

Post by *risk »

Thank you MVV and hacker for your response.

MVV, nice batch file that will get a lot of use.
sorcar
Member
Member
Posts: 100
Joined: 2005-04-12, 17:45 UTC
Location: U.S.

Post by *sorcar »

Thanks, MVV for the useful bat file -- and Hacker for this smart key strokes. How much time I could have saved if I could figure it out before!
sybariten
Junior Member
Junior Member
Posts: 79
Joined: 2003-05-29, 17:31 UTC

Post by *sybariten »

This is almost spooky - i havent visited this forum in half a year, i think, and today i realized i wanted to look into an old issue of mine: to create copies of files, easily.... and this is one of the top posts. :shock:

Anyhooow.... my wish is slightly different than risks: i would ideally like to just select the tile text.txt, press some kind of button or menu choice, and then have a copy called text_130515_133708.txt
(a date and a clock stamp have been inserted)

Do i also have to look into external solutions for this? Doesnt TC have built-in functionality to copy files, and build a filename from date info?

Cheers
User avatar
MVV
Power Member
Power Member
Posts: 8711
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Post by *MVV »

Code: Select all

@echo off
if -%1==- echo Parameters: %%P%%N & pause & goto :EOF
copy %1 "%~dpn1_%date:~8,2%%date:~3,2%%date:~0,2%_%time:~0,2%%time:~3,2%%time:~6,2%%~x1"
You can easilly create user-command and assign a hotkey for it.
User avatar
HolgerK
Power Member
Power Member
Posts: 5411
Joined: 2006-01-26, 22:15 UTC
Location: Europe, Aachen

Post by *HolgerK »

Button using nircmd:

Code: Select all

TOTALCMD#BAR#DATA
C:\Tools\Sys(Internals)\NirSoft\nircmd.exe
shellcopy "%N" "%O_~$currdate.yyMMdd$_~$currtime.HHmmss$.%E"
%COMMANDER_PATH%\WCMICONS.DLL,62
Copy File under cursor with Timestamp in Name


-1
Regards
Holger
sybariten
Junior Member
Junior Member
Posts: 79
Joined: 2003-05-29, 17:31 UTC

Post by *sybariten »

MVV wrote:

Code: Select all

@echo off
if -%1==- echo Parameters: %%P%%N & pause & goto :EOF
copy %1 "%~dpn1_%date:~8,2%%date:~3,2%%date:~0,2%_%time:~0,2%%time:~3,2%%time:~6,2%%~x1"
You can easilly create user-command and assign a hotkey for it.
Thank you!
I added a new entry to the start menu, used this bat file as Comand and then %P%S as Parameter. Seems to work.

But dang, batch syntax is messy... i didnt understand much. There is probably something odd with the date syntax there 'cause my files came out as file_153-20_154629.ext , but the timestamp is the important one so thats no big deal.
sybariten
Junior Member
Junior Member
Posts: 79
Joined: 2003-05-29, 17:31 UTC

Post by *sybariten »

HolgerK wrote:Button using nircmd:

Code: Select all

TOTALCMD#BAR#DATA
C:\Tools\Sys(Internals)\NirSoft\nircmd.exe
shellcopy "%N" "%O_~$currdate.yyMMdd$_~$currtime.HHmmss$.%E"
%COMMANDER_PATH%\WCMICONS.DLL,62
Copy File under cursor with Timestamp in Name


-1
Regards
Holger
IIUC, nircmd is a way to do these things a bit more silently.... with MVVs bat file above, i did get a "DOS window" for half a second or so. Is there really no way to avoid this, with plain BAT files?

cheers
User avatar
MVV
Power Member
Power Member
Posts: 8711
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Post by *MVV »

You can set 'minimized' flag for command.
User avatar
Stefan2
Power Member
Power Member
Posts: 4281
Joined: 2007-09-13, 22:20 UTC
Location: Europa

Post by *Stefan2 »

sybariten wrote:
MVV wrote:

Code: Select all

@echo off
if -%1==- echo Parameters: %%P%%N & pause & goto :EOF
copy %1 "%~dpn1_%date:~8,2%%date:~3,2%%date:~0,2%_%time:~0,2%%time:~3,2%%time:~6,2%%~x1"
You can easilly create user-command and assign a hotkey for it.
Thank you!
I added a new entry to the start menu, used this bat file as Comand and then %P%S as Parameter. Seems to work.

But dang, batch syntax is messy... i didnt understand much. There is probably something odd with the date syntax there 'cause my files came out as file_153-20_154629.ext , but the timestamp is the important one so thats no big deal.
>> my files came out as file_153-20_154629.ext

The above batch is for date strings like "15.05.2013"

Which is yours?

Open a DOS-Box and type 'date' <enter> <enter>

.
User avatar
MVV
Power Member
Power Member
Posts: 8711
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Post by *MVV »

Stefan2 wrote:The above batch is for date strings like "15.05.2013"

Which is yours?
That's correct, I'm from Russia. :)

You can change it as you need. %date:~8,2% means that you take 2 characters at position 8 (starting from 0) from %date% string, you only need to change starting numbers for year, month and day to get it working.

Code: Select all

2013-05-15
0123456789
So if your date format is 2013-05-15, try this:

Code: Select all

@echo off 
 if -%1==- echo Parameters: %%P%%N & pause & goto :EOF 
 copy %1 "%~dpn1_%date:~2,2%%date:~5,2%%date:~8,2%_%time:~0,2%%time:~3,2%%time:~6,2%%~x1"
Post Reply