Sequential file backup

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
drgt
Posts: 158
Joined: 21 Sep 2010 02:22
Location: Greece

Sequential file backup

#1 Post by drgt » 12 Oct 2023 01:40

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

pieh-ejdsch
Posts: 239
Joined: 04 Mar 2014 11:14
Location: germany

Re: Sequential file backup

#2 Post by pieh-ejdsch » 03 Nov 2023 11:58

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

drgt
Posts: 158
Joined: 21 Sep 2010 02:22
Location: Greece

Sequential file backup

#3 Post by drgt » 14 Nov 2023 08:38

Thanks but assuming we call the script test.bat how exactly is it used?
I.E what is the complete command?

pieh-ejdsch
Posts: 239
Joined: 04 Mar 2014 11:14
Location: germany

Re: Sequential file backup

#4 Post by pieh-ejdsch » 15 Nov 2023 06:25

You can drag one or more folders or files onto the batch.
This corresponds to the full path as a parameter.

drgt
Posts: 158
Joined: 21 Sep 2010 02:22
Location: Greece

Sequential file backup

#5 Post by drgt » 15 Nov 2023 14:50

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?

Batcher
Posts: 74
Joined: 16 Apr 2009 10:36

Re: Sequential file backup

#6 Post by Batcher » 15 Nov 2023 19:21

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

Post Reply