Simple example of batch processing if and goto

Updated on technology 2024-02-27
10 answers
  1. Anonymous users2024-02-06

    rem sets the date format to yyyymmdd

    if %date%==20080806 goto doitrem If the time is equal to 20080806 jump to the designator doitrem If the time is not equal to, proceed to the next step.

    notdoit

    Echo time isn't up yet.

    pause.

    goto start

    rem jumps back to the top.

    doitrem This is the designator doit

    rd d:\xx\ /s/q

    The echo is over, the deletion is over.

    pause.

    ps: I used the batch processing that I wrote to delete a folder on a specified date as an example.

  2. Anonymous users2024-02-05

    If and for are two powerful commands in batch processing, and I have a detailed description of them.

    This sentence will give you a simple if

    If is used to judge, and is a command to implement the branch.

    echooffset

    Pa = Enter a number:

    if%a%gtr10

    echo the number you entered is greater than 10

    else(if

    a%equ10(

    echo you enter 10

    elseecho

    The number you entered is less than 10))).

    pause and the goto command is to be executed in conjunction with the tag.

    echooff:start

    set pa=Please enter a character (q exit):

    if/i%a%"=="q"

    gotoendecho

    You entered %a%.

    gotostart

    endpause

  3. Anonymous users2024-02-04

    goto

    Specify the jump to the tag, and when the tag is found, the program will process the command from the next line.

    Syntax: goto tag name (tag name is a parameter that specifies the row in the batcher to which it is turned).

    Goto generally appears with judgment.

    An example is as follows:

    set p a=Please enter a number:

    rem prompts for a number, and reads the input.

    if "%a%"=="1" goto 1

    rem If the value of a is 1, it will be adjusted to the 1 tag to run. The next sentence will not be displayed.

    echo is not 1

    goto end

    1echo input is 1

    end

  4. Anonymous users2024-02-03

    Because the script continues to execute the command that shows 2 after 1 is displayed, there will be a continuous display.

    Please jump or truncate after the previous display ends.

  5. Anonymous users2024-02-02

    Take a closer look at if ?should be able to grasp the writing of having an else clause or branch containing multiple lines.

  6. Anonymous users2024-02-01

    @echo off

    setlocal enabledelayedexpansion

    clscolor 0a

    menuecho big bag big bag big bag.

    echo Please enter the serial number of the selected item:

    set /p dx=

    if "%dx%"=="1" goto id1

    if "%dx%"=="2" goto id2

    if "%dx%"=="3" goto id3

    set dx=&goto menu

    id1for /f "eol=d delims=" %%i in ( do >>echo %%i

    set a=0

    for %%x in (351850,352150,358140,358141,358142,358143,358144) do (

    set /a a+=1

    set x=%%x

    echo dlc00!a!=!x!

    goto end

    id2for /f "eol=d delims=" %%i in ( do >>echo %%i

    set a=0

    for %%x in (352150,358140,358141,358142,358143,520520,520521) do (

    set /a a+=1

    set x=%%x

    echo dlc00!a!=!x!

    goto end

    id3goto end

    enddelrenstart .\

  7. Anonymous users2024-01-31

    It's normal, you can't copy it directly and then leave it unmodified, because the directly copied will automatically have spaces added at the end of each line. So you have to delete, the following is the test screen, everything is fine.

  8. Anonymous users2024-01-30

    @echo off

    set n="%computername%"

    if %n%=="wks001" goto 001

    if %n%=="wks002" goto 002

    if %n%=="wks006" goto 006

    goto end

    copy j: 001 account list. INI D: J: 001 OPPO script Y

    Start J: 001 OPPO script

    goto end

    Copy J: 002 Account List. INI D: J: 002 OPPO script y

    Start J: 002 OPPO script

    goto end

    copy j: 006 account list. ini d: j: 006 oppo script y

    Start J: 006 OPPO script

    goto end

    copy j: 007 account list. ini d: j: 007 oppo script y

    Start J: 007 oppo script

    endpause

    When using variables, you need to enclose them with %%, e.g. %n%Because variables are assigned with quotation marks, they should also be quoted when comparing. Determine that your machine name is in a fixed format based on your batch processing**, and if so, you can directly take the machine name as a variable.

    ** As follows: echo off

    set "n=%computername%"

    copy j: 3% account list. ini d: j: :3% oppo script y

    Start J: %n: 3% oppo script

    pause

  9. Anonymous users2024-01-29

    Write exit on the line below the last if

    If you don't terminate the if comparison, of course the order will continue to be executed!

    Also, write exit on the line below each start and copy, otherwise the following command will be executed.

    Anyway, you remember that as long as it's basic about the jump subcommand function, you need to terminate it unless you jump again.

  10. Anonymous users2024-01-28

    if "conditions" then

    The condition is true"

    Execute this statement if the else condition is false"

    endgoto "Line number or example number"

    For example: if a=1 then

    b=aelse

    goto bbb

    endbbb:b=c

Related questions
9 answers2024-02-27

echo off the beginning of the stove and the beginning of the blind carry the sacred mountain. >>>More

19 answers2024-02-27

echo off

del C: Windows System32 adds this batch to the startup of the menu. >>>More

8 answers2024-02-27

Others are keen to look for traces left by aliens in ancient times. They believe that the round masks of the figures on the murals of the Sahara Desert, the megalithic buildings of Easter Island and South America, and the pyramids, among other unexplained prehistoric wonders, are related to aliens. Other scholars have put forward various ideas such as that humans are descendants of aliens, or that some peoples of mankind (such as the Maya) are descendants of aliens mating with earthlings. >>>More

2 answers2024-02-27

It is said that the relationship between classmates is the most intimate and irreplaceable. But sometimes we are at a loss, and we don't know how to deal with our classmates. Here are some ways to help you easily deal with the relationship between your classmates and successfully reap a sincere friendship. >>>More

8 answers2024-02-27

1. A is used in front of words that begin with a consonant letter, or a vowel that is pronounced as a consonant and begins with a brother's letter >>>More