I want to make a backup of a certain file manually each time i open a bat file, but I don't want to overwrite the file each time it's backed up, instead I want to create several copies of the file and save it with a sequential file name. That's because the file changes very frequently.
Example:
MyFile (1).txt
MyFile (2).txt
MyFile (3).txt
MyFile (4).txt
Or without brackets would be better, anyway I don't mind brackets or anything I just don't want to overwrite the file and create new copies each time it's backed up.
Another way that I thought about doing this is by putting the file into sequential folders, that'll be okay too.
Anyways, I am pretty sure this is very easy I just need the code I am not being able to find anything from google.
Thanks everyone!
Make Backup of specific files with sequential filename
Moderator: DosItHelp
Re: Make Backup of specific files with sequential filename
Adding a date and time in a format that sorts correctly is a better way to handle this.
Re: Make Backup of specific files with sequential filename
foxidrive wrote:Adding a date and time in a format that sorts correctly is a better way to handle this.
can you provide a code? i am not that good at code...
i have found this on google but its not exactly what i want and it doesnt work:
Code: Select all
@echo off
:: variables
set backupdir="%USERPROFILE%\Desktop\folder1"
set backupcmd=xcopy "%USERPROFILE%\Desktop\folder2\file.txt"
echo ### Backing Up Saves...
xcopy /s "%USERPROFILE%\Desktop\folder1\file.txt" "%backupdir%/%time%"
echo Backup Complete!
@pause
can anyone please correct that code so it does what i described in the first post ?? thanks!
Re: Make Backup of specific files with sequential filename
Test this:
Code: Select all
:: The first four lines of this code will give you reliable YY DD MM YYYY HH Min Sec variables in XP Pro and higher.
@echo off
for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a"
set "YY=%dt:~2,2%" & set "YYYY=%dt:~0,4%" & set "MM=%dt:~4,2%" & set "DD=%dt:~6,2%"
set "HH=%dt:~8,2%" & set "Min=%dt:~10,2%" & set "Sec=%dt:~12,2%"
set "datestamp=%YYYY%%MM%%DD%" & set "timestamp=%HH%%Min%%Sec%"
copy "my file.txt" "c:\wherever-you-want-it\my file %datestamp%_%timestamp%.txt"