You could use time
to create a directory name:
set butime=%time:~0,2%%time:~3,2%%time:~6,2% mkdir %butime%
Я пытаюсь создать резервную копию для сохранения игры Assassins Creed 3 каждые x минут, но папка и ее файлы перезаписываются каждый раз, пожалуйста, предложите мне код, чтобы каждая резервная копия находилась в разных папках. Извините за плохой английский .
cls @echo off color 0C echo. echo Start Backup echo. pause :start cls echo. echo Backup started echo. xcopy "source" "destination" /s /y /e timeout /t 5 goto start
You could use time
to create a directory name:
set butime=%time:~0,2%%time:~3,2%%time:~6,2% mkdir %butime%
If you wouldn't mind making the directories' names based on date and time (which I would think you probably wouldn't mind in this situation), then maybe this batch file would work. Also, this would help automate it a bit. The reason I'm making the check for if the game is running is because there isn't any real reason to make a backup when the game has been off for a while.
Create this batch file:
@echo off setlocal enabledelayedexpansion enableextensions cls rem Color is taken care of in the task call. %= ============================================================== =% rem * Take this section out if you want it to make backups even when rem * you're not playing the game. echo Checking if game is running... md "%tmp%\cmdtmp" set tmpdir=%tmp%\cmdtmp tasklist /fo csv /nh /fi "imagename eq %NameOfACExectuable%" /fi "status eq running" > "%tmpdir%\tmp.txt" set /p tasklist= < "%tmpdir%\tmp.txt" del "%tmpdir%\tmp.txt" rd "%tmpdir%" /s /q set tasklist= set tmpdir= %= ============================================================== =% set image= for /f "tokens=1 delims=," %%I in (!tasklist!) do ( set tmpvar=%%~I for %%J in (!tmpvar!) do if not defined image set image=%%~xJ rem * The file extension needs checked so image doesn't become rem * set with output saying that no files have been found. rem * This section has to be a bit complicated because there rem * isn't any straightforward way to get an extension out of rem * an environment variable. ) if not defined image goto :eof echo. echo Backup has now started. rem * This is to ensure that the date/time format is consistent rem * (we likely don't use the same date/time format). set X= for /f "skip=1 delims=" %%x in ('wmic os get localdatetime') do if not defined X set X=%%x set datetime=!X:~0,4!!X:~4,2!!X:~6,2!_!X:~8,2!!X:~10,2!!X:~12,2! set bkupdir="%WhereverYouWantToMakeTheBackup%" md "%bkupdir%\savebackup_!datetime!" set thisbkupdir="%bkupdir%\savebackup_!datetime!" xcopy "%WhereYourACGameSaveIs%" "!thisbkupdir!" /e /y /c /q echo. echo Backup completed. Exiting... timeout /t 5 /nobreak exit
Create a task (there are two routes to do this):
%comspec% /t:0C /c "Drive:\Dir\To\YourBatchFile.bat"
.schtasks /create /tn WhatYouWantToNameYourTask" /tr "'%comspec%' /t:0C /c \"%DirToBat%\"" /sc minute /mo XPlease note that the quotes being passed as arguments to %comspec% MUST be escaped as shown. Also, the number of minutes here are something you can more finely control than in the UI.
One item of note: The batch file is written to stop immediately after seeing that the game isn't running, and it makes the check before making any preparations to back up anything. If you don't want that, then take out the sections marked by commented equal signs: %= ============= =%
Also, feel free to translate the echo
lines if you wish.