Page 1 of 1

Sequential file backup

Posted: 12 Oct 2023 01:40
by drgt
Hello everyone

I need to backup a File.ext in the same folder renaming the backup to: File.1.ext for the 1st time, File.2.ext for the second time, etc
(Or another perhaps easier renaming method)

Can you help me with the code?

Thanks

Re: Sequential file backup

Posted: 03 Nov 2023 11:58
by pieh-ejdsch
Hallo drgt,
What you are looking for is a small versioning of different states of one and the same file or files or folders.

You can find the appropriate script here:

viewtopic.php?t=7903#p52948

Just read the description

Phil

Sequential file backup

Posted: 14 Nov 2023 08:38
by drgt
Thanks but assuming we call the script test.bat how exactly is it used?
I.E what is the complete command?

Re: Sequential file backup

Posted: 15 Nov 2023 06:25
by pieh-ejdsch
You can drag one or more folders or files onto the batch.
This corresponds to the full path as a parameter.

Sequential file backup

Posted: 15 Nov 2023 14:50
by drgt
What is the OS requirement for this?

I wanted to use it also in an old xp sp2 machine.

Ok. I drag a file onto the batch file?

Where will the target file go?

Re: Sequential file backup

Posted: 15 Nov 2023 19:21
by Batcher
DragOneFileOnMe.bat

Code: Select all

@echo off
if "%~1" equ "" (
    echo Please close it, drag one file on me.
    pause
    goto :eof
)
cd /d "%~dp0"
set "n=1"
call :GetNextName "%~n1" "%~x1"
copy "%~1" "%NewName%%~x1"
exit /b

:GetNextName
if exist "%~1.%n%%2"  (
   set /a n+=1
   goto :GetNextName
)
set "NewName=%~1.%n%"
goto :eof