LoginSignup
3
4

More than 5 years have passed since last update.

USBメモリをFAT16でフォーマットするバッチファイル

Posted at

http://qiita.com/7of9/items/51eee711dfb09869ec20
この記事のコメントのやりとりで、ドライブ番号が不定な環境でも自動処理できないか考えてみた。
リムーバブルメディアが1個だけという条件付きですが、固定ドライブの数が不定であってもUSBメモリをフォーマットすることができました。

@echo off

set DRIVENUM=
for /f "usebackq tokens=1-3" %%a in (`cmd /c "wmic diskdrive get mediatype,index"`) do if "%%b"=="Removable" set DRIVENUM=%%a

(
echo.select disk %DRIVENUM%
echo.clean
echo.create partition primary size=2048
echo.format fs=fat quick
echo.assign
) > %temp%\format.txt

diskpart /s %temp%\format.txt

いきなりこれを実行したりせずに、最後の行のdiskpart /sをtypeに変えてドライブ番号が正しいか確認しましょう。

3
4
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
4