cmd - batch file to backup file -
i have below script take backup of file when user logs in. saved in batch file. creates log when file copied. want edit script saves date , time when file has been copied... please need ur help thanks
@echo off rem re-create documents xcopy "c:\users\user1\desktop\the folder\the file.xlsm" "c:\users\user1\desktop\the folder\backup\" /c /r /d /y > "c:\users\user1\desktop\the folder\backup\xcopy.log"
this works independent of regional date/time format:
for /f "tokens=1" %%i in ('wmic os localdatetime ^|find "20"') set dt=%%i rem dt format yyyymmddhhmmss echo datetimestring: %dt% rem here can format date/time need it: set dat=%dt:~4,2%-%dt:~2,2%-%dt:~0,4% echo formatted datetimestring: %dat% set tim=%dt:~8,4% echo time unformatted without date: %tim% set tims=%dt:~8,2%:%dt:~10,2%:%dt:~12,2% echo time formatted: %tims%
note: if want write date/time filename, best selection yyyymmddhhmm format, because files sort chronilogical.
xcopy "source" "destination" > "path\xcopy-%dt%.log"
to write date/time file, utilize
echo %dat%-%tims% >> "path\xcopy.log"
batch-file cmd
No comments:
Post a Comment