![]() IF "%filetime:~0,1%"=" " SET filetime=0%filetime:~1,3% Some other notes about batch filesĭO part can be split over lines: for /f "tokens=1-3 delims=- " %%a in ('date /t') do ( The following line adds leading zero if necessary. Sat ), the command should be changed to FOR /F "tokens=2-3 delims=/ " %%a IN ('date /t') DO (SET filedate=%%c_%%a_%%b) So if your date format is ddd MM/dd/yyyy (e.g. The option delims specifies the set of delimiters. We use these variables to set the variable filedate. In our case we use first to third tokens, first token is assigned to variable a, second token is assigned to variable b, and third is assigned to variable c. When option tokens is specified, additional variables are allocated. In our case we get one line result of the command date /t and parse it using the specified options tokens and delims. You can read description of the command running FOR /?. This command reads and processes line by line all files from the files-set. FOR /F %%variable IN (file-set) DO command This line gets the date, parses it assuming format yyyy-MM-dd and builds the variable filedate in format yyyy_MM_dd. Let’s consider the line: FOR /F "tokens=1-3 delims=- " %%a IN ('date /t') DO (SET filedate=%%a_%%b_%%c) But this might be not the best solution, the other option is to adjust the script. So the easiest way to make it work is to adjust server date and time short format to yyyy-MM-dd and Hmm in Region and Language settings. It uses command line tool DATE to get the current date and system environment variable %TIME% to get the current time. The above script assumes the server yyyy-MM-dd as the date format and Hmm as the time format ( H stands for 24 hours time format). ![]() REM do something redirecting result to %logfilename%ĮCHO See the logfile: %logfilename% Adjusting date pattern to correspond server settings SET logfilename=C:\Logging\Log_%filedate%_%filetime%.log REM prepare log file name in format Log_yyyy_MM_dd_HHmm.log REM if time in format Hmm - add leading zero How to build the log file name with timestamp in the format Log_yyyy_MM_dd_HHmm.log.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |