|
@echo off
setlocal EnableDelayedExpansion
call :DisposeLanguage
if not "!errorlevel!"=="0" (echo language is unknown.)&&(goto end)
call :GetUDisk
if not "!errorlevel!"=="0" goto end
echo your U disk is ***(!uDisk!)***
:end
pause
exit/b 0
:GetUDisk
setlocal
call :GetUDiskNumber
if not "!errorlevel!"=="0" (echo U Disk not found)&&(exit /b 1)
rem echo !uDiskNumber!
set "uDiskNumber=!uDiskNumber:~0,1!"
for /f "tokens=4 delims= " %%a in ('^(echo sele disk %uDiskNumber%^&echo sele part 1^&echo detail part^) ^|diskpart ^| find /I "%movable%"') do (
set "uDisk=%%a:"
)
if "!uDisk!"=="" exit /b 1
endlocal&set uDisk=%uDisk%
exit /b 0
:GetUDiskNumber
setlocal
call :SetDiskType
set uDiskNumber=
for /l %%a in (0,1,!diskMaxNumber!) do (
if "!disk%%a!"=="!uType!" (
if "!uDiskNumber!"=="" (
set "uDiskNumber=%%a"
) else (
set "uDiskNumber=!uDiskNumber!,%%a"
)
)
)
if "!uDiskNumber!"=="" exit/b 1
:success
endlocal&set uDiskNumber=%uDiskNumber%
exit /b 0
:SetDiskType
call :GetDiskCount
set /a diskMaxNumber=!diskCount!-1
for /l %%a in (0,1,!diskMaxNumber!) do (
for /f "tokens=2 delims=:" %%b in ('^(echo sele disk %%a^&echo detail disk^) ^|diskpart ^| find /I "!type!"') do (
if not "%%b"=="" (set disk%%a=%%b)
)
)
for /l %%a in (0,1,!diskMaxNumber!) do (
echo disk %%a type is !disk%%a!
)
exit /b 0
:GetDiskCount
setlocal
set /a n=0
for /f "tokens=2,4 delims= " %%a in ('echo list disk ^|diskpart ^| find /I "!online!"') do (
set /a n=!n!+1
)
set diskCount=!n!
endlocal&set diskCount=%diskCount%
exit /b 0
:DisposeLanguage
setlocal
for /f "tokens=3 delims= " %%a in ('dir ^| find /I "bytes free"') do set diskSpace=%%a
if not "!diskspace!"=="" (
set lang=en_US
goto lang
)
for /f "tokens=3 delims= " %%a in ('dir ^| find "可用字节"') do set diskSpace=%%a
if not "!diskspace!"=="" (
set lang=zh_CN
goto lang
)
set lang=other
:lang
endlocal&set lang=%lang%
call :LanguageSet
if not "!errorlevel!"=="0" (echo language unknown.)&&(exit /b 1)
exit /b 0
:LanguageSet
setlocal
if "%lang%"=="en_US" (
echo your language is English.
set online=Online
set type=Type
set uType= USB
set movable=Removable
)
if "%lang%"=="zh_CN" (
echo 你的语言是简体中文。
set online=联机
set movable=可移动
set type=类型
set uType= USB
)
if "%lang%"=="other" (exit /b 1)
if "%lang%"=="" (exit /b 1)
endlocal&set movable=%movable%&set type=%type%&set online=%online%&set uType=%uType%
exit /b 0
看你写得辛苦,给你一个我写的获取U盘盘符的纯批处理。你柔合进boot.wim会有奇效。直接就不需要输入U盘盘符了,说老实话,你这个写得太简单了,连MBR和GPT都不判定,而且盘符全部写死,如果哪个盘恰好是W盘,不晓得会不会有问题。 |
|