【原创】bat脚本,自动识别U盘并且格式化 |
|
红叶遍山
L12
• 2022-03-10 • 回复 1 • 最后编辑于2022-03-10 23:43 • 只看楼主
• 举报
|
直接上源码:
@echo off
rem 提取所有的disk
echo list disk |diskpart >listdisk.txt
rem 提取disk行
set s= -2
(for %%i in (".\listdisk.txt") do (
setlocal enabledelayedexpansion
for /f "delims=" %%j in ('type "%%i"') do (
set /a n+=1 & set "_!n!=%%j"
)
for %%j in (!s!) do (
set /a "x = (n+1) * (%%j>>31&1) + %%j"
for %%k in (!x!) do (echo;%%~ni !_%%k!)
)
endlocal
)) > Result.txt
rem 提取disk id
for /f "tokens=3 delims= " %%A in (Result.txt) do (
set lat=%%A
)
echo disk id =%lat%
ping 127.1 -n 5 >nul 2>nul
rem disk转换
(echo select disk %lat% &echo clean &echo creat partition primary &echo format quick label="yx" &echo assign letter=t &echo exit) >222.txt
diskpart /s 222.txt
rem 删除tmpe文件
del .\Result.txt
del .\listdisk.txt
del .\222.txt
echo 格式转化成功
ping 127.1 -n 5 >nul 2>nul