问题描述
- bat 运行错误 'if'不是内部或外部命令
-
@echo off
setlocal enabledelayedexpansion
echo.
set Drive=0
For /F "Skip=1" %%i in ('Wmic Logicaldisk Where "DriveType=3" Get Name') Do (
set /a Drive=!Drive!+1
set Drive[!Drive!]=%%i
)
set /a Drive=!Drive!-1
set var=1
:DriveChoose
echo.
set /p output=请选择安装磁盘(<nul
for /l %%i in (1,1,!Drive!) do (
call set /p output=%%Drive[%%i]::=%%/<nul)
echo )
set /p enter=请输入安装磁盘:
for /l %%i in (1,1,!Drive!) do (
call set "output=if [%%%%enter%%%%]==%%Drive[%%i]::=%% do (set var=0)"
!output!
)
if %var%==1 (goto :DriveChoose)
echo ............
pause
解决方案
set Drive=0
For /F "Skip=1" %%i in ('Wmic Logicaldisk Where "DriveType=3" Get Name') Do (
set /a Drive+=1
set Drive[!Drive!]=%%i
)
set /a Drive=!Drive!-1
set var=1
:DriveChoose
cls
echo.
set /p output=请选择安装磁盘(<nul
for /l %%i in (1,1,!Drive!) do (
call set /p output=%%Drive[%%i]::=%%/<nul)
echo )
set /p enter=请输入安装磁盘:
for /l %%i in (1,1,!Drive!) do (
set Drive[%%i]=!Drive[%%i]:~0,1!
if /i [!enter!]==!Drive[%%i]!
if /i [!enter!]==!Drive[%%i]!:
if /i [!enter!]==!Drive[%%i]!:/
)
if %var%==1 (goto :DriveChoose)
时间: 2024-11-05 14:56:18