I am trying to creating batch file. How to use user input in selecting partition no? I want to format some partitions only using diskpart
. I already learn how to select disk number but I want to learn select partition number also. Sometimes partition number changed. So how can I user input for selecting partition number?
I am doing below now. But I want at time of selecting partition, it should ask me to select partition number also, but how?
@echo off
cd /d"%~dp0"
rem == List Disk and List Partitions ======================
echo >diskpart.txt List Disk
diskpart /s diskpart.txt
set /p Disk=Please enter the disk number:
if "%Disk%"=="" goto :eof
echo > diskpart.txt Select disk %disk%
echo >> diskpart.txt list partition
diskpart /s diskpart.txt
echo ============= Please check your Disk and all Partition numbers before continue =============
pause
rem == List Disk Again for Final Confirmation ======================
echo >diskpart.txt List Disk
diskpart /s diskpart.txt
set /p Disk=Please enter the disk number:
if "%Disk%"=="" goto :eof
echo > diskpart.txt Select disk %disk%
rem == 1. Format System partition ======================
echo >> diskpart.txt select partition 1
echo >> diskpart.txt format quick fs=fat32 label="System"
rem == 2. Format Windows partition ========================
echo >> diskpart.txt select partition 3
echo >> diskpart.txt format quick fs=ntfs label="Windows"
rem == 3. Format Recovery tools partition ================
echo >> diskpart.txt select partition 4
echo >> diskpart.txt format quick fs=ntfs label="Recovery"
echo >> diskpart.txt list partition
diskpart /s diskpart.txt
pause
(Since I'm a new to stackoverflow I cannot use comment for clarification.)
As I understood you present the user the diskpart output of
list disk
and want him to select the disk AND the partition at the same time?Fetch all availabel disks and keep them in a list an than call diskpart for each disk and do
list partition
. That way the user sees all disks with all their partitions and can enter disk and partition number at once.Additionally you may keep track of alls disk and partition numbers like in %DiskList% and verify that the user input makes sense.
With this diskpart-for-loops you could also use
detail disk
anddetail volume
after the disk selection to use those informations for further verification.Another way to select disk and partition at once is to use select
volume
. This requires the partition to have a drive letter assigned which does not apply to the "System" (boot) partition.EDIT You almost found the answer youself. You have already listed the disks and asked the user for a disk number. Do the same for the partition number. The only difference is that you need to select a disk before you can select a partition.