cmd 語法問題

我做了一個批次檔可是後來發現有點問題就是當我先執行1的時候執行完畢後馬上要執行2的時候就會發生錯誤就還要再打一次2才可以執行該怎嚜修改才是正確的?

以下是我的語法

@echo off

:start

cls

ECHO.

ECHO.   

ECHO   ╔═══════════════════════╗

ECHO.

ECHO     1:複製檔案

ECHO.

ECHO     2:移除USB,並關閉本視窗

ECHO.

ECHO 3:關閉視窗

ECHO.

ECHO

ECHO.

ECHO   ╚═══════════════════════╝

ECHO.

set /p CHS= 選擇項目(輸入完後按Enter):

if Errorlevel 1 (goto Error) else (goto okay)

:okay

if %CHS% EQU 1 (goto 1) else (goto other)

:1

cls

echo.set /p file=請輸入欲複製的檔案或資料夾名稱:

set /p filepath=請輸入存放資料夾路徑:

echo -------------------------檔案確認------------------------------

echo.

echo 您要複製的檔案或資料夾:%file% 即將複製到:%filepath%

echo.

echo -------------------確認完畢!任意鍵執行-------------------------

echo.

pause >nul

xcopy /s /c "%file%" "%filepath%"

echo.

echo 已複製完畢,請確認檔案!

echo.

echo 按任意鍵回到主目錄

pause >nul

goto start

:other

if %CHS% EQU 2 (goto 2) else (goto other)

:2

start USB_Disk_Eject.exe

exit

:otherif %CHS% EQU 3 (goto 3) else (goto error)

:3

echo.

echo 任意鍵關閉...

pause>nul

exit:Error

cls

echo 輸入錯誤 任意鍵繼續...

pause>nul

dir>nul

cls

goto start

1 Answer

Rating
  • Moore
    Lv 5
    10 years ago
    Favorite Answer

    @echo off

    :start

    verify on ---->加這個,試看看吧,您的問題我覺得是出在%Errorlevel%

    cls

    ECHO.

    以下略.....

Still have questions? Get your answers by asking now.