Setting a windows batch file variable to the day of the week

后端 未结 17 1956
南方客
南方客 2020-11-27 20:14

I have a windows batch file that runs daily. Wish to log data into a file and want to rotate it (i.e. having at most the last 7 days worth of data).

Looked into the

17条回答
  •  死守一世寂寞
    2020-11-27 20:34

    If you can change format of short date in the PC to "ffffd yyyy-MM-dd" (only first parameter 'ffffd' is compulsory), then following command returns-

    c:\>vol | date
    The current date is: Mon 2014-12-01
    

    Then you can write you batch file -

    @echo off
    
    vol | date | find /i "sun" > nul 
    if not errorlevel 1 goto SUN
    
    vol | date | find /i "mon" > nul 
    if not errorlevel 1 goto MON
    
          # write block for other week days    
    
    goto END
    
    :SUN
    set fname="sun"
    goto BACKUP
    
    :MON
    set fname="mon"
    goto BACKUP
    
          # write block for other week days
    
    :BACKUP
    echo %fname%
    
    :END
    

提交回复
热议问题