w10install/04_FormatStick.cmd
Michael H.G. Schmidt a0bce5123b .
2022-09-09 21:08:15 +02:00

112 lines
2.0 KiB
Batchfile

@echo off
set T=c:\TEMP
set DPARTSCRIPT=%T%\diskpart.txt
rem create temp directory ...
mkdir %T% 1>nul 2>nul
echo ====================
echo Format USB Stick ...
echo ====================
echo.
echo Showing disk list ...
> %DPARTSCRIPT% (
@echo.list disk
@echo.exit
@echo.
)
diskpart /s %DPARTSCRIPT% 2>nul
set DISK=
:askdisk
set /p DISK="Please select a disk: "
> %DPARTSCRIPT% (
@echo.select disk %DISK%
@echo.exit
@echo.
)
diskpart /s %DPARTSCRIPT% 1>nul 2>nul
if %ERRORLEVEL% EQU 0 (
echo OK using disk %DISK%
GOTO CONT1
) else (
echo ERROR: please select a valid disk number!
)
goto askdisk
:CONT1
set FS=
:askfs
set /p FS="Please select filesystem (exfat or fat32) [exfat]: "
if /i "%FS%" EQU "fat32" (
GOTO CONT2
)
if /i "%FS%" EQU "exfat" (
GOTO CONT2
)
if /i "%FS%" EQU "" (
set FS=exfat
GOTO CONT2
)
echo Please enter "exfat" or "fat32".
goto askfs
:CONT2
echo selected: %FS%
set LABEL=
set /p LABEL="Please enter a label for the new disk: "
echo WARNING ! This will DELETE ALL data on disk number [ %DISK% ]
echo.
set answer=
:askyes
set /p answer="REALLY delete disk %DISK% (Y/N)? "
if /i "%answer:~,1%" EQU "Y" (
GOTO CONT3
)
if /i "%answer:~,1%" EQU "N" (
echo ABORT.
del /F %DPARTSCRIPT% 1>nul 2>nul
exit /b
)
echo Please type Y or N.
goto askyes
:CONT3
rem =====
rem MAIN
rem =====
> %DPARTSCRIPT% (
@echo.select disk %DISK%
@echo.clean
@echo.convert MBR
@echo.create partition primary
@echo.select partition 1
@echo.format fs="%FS%" LABEL="%LABEL%" quick
@echo.active
@echo.exit
@echo.
)
diskpart /s %DPARTSCRIPT%
if %ERRORLEVEL% NEQ 0 (
echo ERROR: while formatting the disk!
del /F %DPARTSCRIPT% 1>nul 2>nul
exit /b
)
echo READY.
echo USB stick formatted.
echo.
rem cleanup ...
del /F %DPARTSCRIPT% 1>nul 2>nul
rem =====
rem END
rem =====