I am looking into modifying some code to add a date format to a batch file, this is the code we are using and it is on a Windows XP embedded machine
The date format can be as simple as 16012015
The file saves to the D drive then copies to a USB drive if we have one in, the storage on the PC is only small which is why we delete the file every time we backup
REM #### Creation of the ZIP file ####
Del %BackupPath%\%ZipName%
7z a -tzip %BackupPath%\%ZipName% %BackupPath%\Backup\
REM #### Copy to USB ####
IF EXIST E: (echo Copie sur disque E:
copy %BackupPath%\%ZipName% E: /y )
IF EXIST F: (echo Copie sur disque F:
copy %BackupPath%\%ZipName% F: /y )
IF EXIST G: (echo Copie sur disque G:
copy %BackupPath%\%ZipName% G: /y )
IF EXIST H: (echo Copie sur disque H:
copy %BackupPath%\%ZipName% H: /y )
IF EXIST I: (echo Copie sur disque I:
copy %BackupPath%\%ZipName% I: /y )
I find it best to have timestamps in YYYYMMDD format so that they will sort chronologically.
for /f "usebackq tokens=1,2,3,4,5,6,7 delims=/:. " %%a in (`echo %DATE% %TIME%`) do set NOW=%%d%%b%%c_%%e%%f%%g
@echo now: %NOW%
set NewZipName=Backup-%NOW%.zip
This will print out a date in YYYYMMDD_HHMMSS format. Example output: 20150115_165438
If you don't care about the date format and you're happy with the format used by %DATE%
then something as simple as this should work:
REM Remove slashes and spaces from the date:
set d=%date:/=%
set d=%d: =%
set NewZipName=Backup-%d%.zip
On my PC %DATE%
returns Thu 01/15/2015
so that's why I'm removing the /
and space above to produce a NewZipName of 'Backup-Thu01152015.zip', but in your case you may have to remove different characters according to your region settings date format...
then and at the end copy %BackupPath%\\%ZipName% G:\\%NewZipName% /y
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.