only do if day… batch file

后端 未结 7 1741
南笙
南笙 2021-02-09 00:43

hello i got a batch file, something like this:

if %day%==monday, tuesday, wednesday, thursday, friday (
goto yes
) else (
goto no
)

Now i know

7条回答
  •  花落未央
    2021-02-09 01:04

    Here is an example bat file that will do this sort of thing I am sure you can think of other ways to use this sample code. For instance anytime you need an "in" list. The tricky bit is the %date:~0,3% this says expand the %date% environment variable and starting at position 0 the beginning of the string return the next 3 characters. You can learn more about this from the "set /?" command.

    example: IsWeekDay.bat

    @echo off
    setlocal
    
    for %%i in (Mon,Tue,Wed,Thu,Fri) do (
        if "%date:~0,3%"=="%%i" goto YES
    )
    
    :NO
    echo No
    goto EOF
    
    :YES
    echo Yes
    
    :EOF
    endlocal
    

提交回复
热议问题