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

后端 未结 17 1992
南方客
南方客 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:46

    I have this solution working for me:

    Create a file named dayOfWeek.vbs in the same dir where the cmd file will go.

    dayOfWeek.vbs contains a single line:

    wscript.stdout.write weekdayname(weekday(date))
    

    or, if you want day number instead of name:

    wscript.stdout.write weekday(date)
    

    The cmd file will have this line:

    For /F %%A In ('CScript dayOfWeek.vbs //NoLogo') Do Set dayName=%%A
    

    Now you can use variable dayName like:

    robocopy c:\inetpub \\DCStorage1\Share1\WebServer\InetPub_%dayName% /S /XD history logs
    

提交回复
热议问题