w10install/06_FormatStick.cmd

134 lines
2.4 KiB
Batchfile
Raw Normal View History

@echo off
set T=c:\TEMP
set DPARTSCRIPT=%T%\diskpart.txt
2021-03-19 18:25:28 +01:00
rem create temp directory ...
mkdir %T% 1>nul 2>nul
2021-03-17 00:22:50 +01:00
echo ====================
echo Format USB Stick ...
echo ====================
echo.
2023-01-02 17:15:02 +01:00
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
2021-03-28 00:49:42 +01:00
if %ERRORLEVEL% EQU 0 (
echo OK using disk %DISK%
GOTO CONT1
) else (
echo ERROR: please select a valid disk number!
)
goto askdisk
:CONT1
2022-09-09 21:08:15 +02:00
set FS=
:askfs
2022-09-25 13:12:13 +02:00
echo.
2022-09-09 21:08:15 +02:00
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%
2022-09-25 13:12:13 +02:00
set SIZE=
:asksize
echo.
echo IMPORTANT: maximum size for FAT32 is 32768!
set /p SIZE="Please enter size in MB [max]: "
if /i "%SIZE%" EQU "" (
GOTO CONT3
)
echo %SIZE%| findstr /r "^[1-9][0-9]*$">nul
if %errorlevel% neq 0 (
echo Please enter an integer number!
goto asksize
) else (
echo selected size = %SIZE% [MB]
set SIZE=size=%SIZE%
)
:CONT3
echo.
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" (
2022-09-09 21:08:15 +02:00
GOTO CONT3
)
if /i "%answer:~,1%" EQU "N" (
echo ABORT.
2021-03-19 18:25:28 +01:00
del /F %DPARTSCRIPT% 1>nul 2>nul
exit /b
)
echo Please type Y or N.
goto askyes
2022-09-09 21:08:15 +02:00
:CONT3
rem =====
rem MAIN
rem =====
> %DPARTSCRIPT% (
@echo.select disk %DISK%
@echo.clean
2022-08-26 11:26:25 +02:00
@echo.convert MBR
2022-09-25 13:12:13 +02:00
@echo.create partition primary %SIZE%
@echo.select partition 1
2022-09-09 21:08:15 +02:00
@echo.format fs="%FS%" LABEL="%LABEL%" quick
@echo.active
2022-12-29 10:49:17 +01:00
@echo.assign
@echo.exit
@echo.
)
2022-08-26 11:26:25 +02:00
diskpart /s %DPARTSCRIPT%
2021-03-28 00:49:42 +01:00
if %ERRORLEVEL% NEQ 0 (
echo ERROR: while formatting the disk!
2021-03-19 18:25:28 +01:00
del /F %DPARTSCRIPT% 1>nul 2>nul
exit /b
)
2021-03-17 00:22:50 +01:00
echo USB stick formatted.
2021-03-19 18:25:28 +01:00
rem cleanup ...
del /F %DPARTSCRIPT% 1>nul 2>nul
2023-01-02 17:15:02 +01:00
echo.
echo ======
echo READY.
echo ======