回复 2# Batcher 感谢大佬的回答,我被assign letter迷惑了,其实不给它指定驱动器号就会顺延到下一个盘符了。去掉 letter就能达到我想要的效果。还有一个问题就是我在U盘上运行,如何防止误操作把U盘也格式化了?- @echo off
-
- :1
-
-
-
-
- echo list disk > diskpart.txt
-
- diskpart /s diskpart.txt
-
- set /p i=请输入选择的磁盘(如0):
-
- echo %i%|findstr /x "[0-3]" >nul||(
- echo 输入错误 &pause>nul
- goto :1)
-
- echo sel disk %%i > diskpart.txt
-
- echo detail disk >> diskpart.txt
- if %%i neq 0 (
- diskpart /s diskpart.txt>DiskInfo.txt
- )
- diskpart /s diskpart.txt>DiskInfo.txt
-
- for /f "tokens=3" %%a in ('type DiskInfo.txt ^| find "类型 :"') do (
- if "%%a" equ "USB" echo ERROR && goto :ERROR
- )
-
-
-
- echo clean >> diskpart.txt
-
- echo convert gpt >> diskpart.txt
-
- echo create partition primary >> diskpart.txt
-
- echo format quick fs=ntfs >> diskpart.txt
-
- echo assign >> diskpart.txt
-
- diskpart /s diskpart.txt
-
- if exist diskpart.txt del /f /q diskpart.txt
-
- if exist DiskInfo.txt del /f /q DiskInfo.txt
-
- :ERROR
- color 4f
- @echo.
-
- @echo An error has been detected.
-
- @echo.
-
- pause >nul
-
- goto :ERROR
-
- pause
复制代码 我加入这段后为什么我不管选择哪个盘都去ERROR那里,麻烦指点一下,谢谢- echo sel disk %%i > diskpart.txt
-
- echo detail disk >> diskpart.txt
- if %%i neq 0 (
- diskpart /s diskpart.txt>DiskInfo.txt
- )
- diskpart /s diskpart.txt>DiskInfo.txt
-
- for /f "tokens=3" %%a in ('type DiskInfo.txt ^| find "类型 :"') do (
- if "%%a" equ "USB" echo ERROR && goto :ERROR
- )
复制代码
|