DISKPART select command doesn't have a "noerr" command for scripti

Discussion in 'Scripting' started by WB, Nov 25, 2008.

  1. WB

    WB Guest

    I'm trying to programmatically delete all partitions from a drive, however
    I'm not sure how many partitions the drive has.

    I thought the script below would work, but if any of the partitions don't
    exist, the script stops execution when trying to select them. This is because
    there is not a "noerr" parameter for selecting the partitions.

    I don't understand what good the "noerr" parameters are when you have to
    select items first, and the select function has no "noerr" parameter so it
    fails???:

    BTW: I cannot use "clean" (please don't ask why)

    select disk 0
    select partition 1
    delete partition noerr
    select partition 2
    delete partition noerr
    select partition 3
    delete partition noerr
    select partition 4
    delete partition noerr
    select partition 0
    delete partition noerr
    select disk 0
    create partition primary size 2000
    format FS=FAT LABEL="PARTITION1" QUICK
    assign letter d
    create partition extended
    create partition logical
    format FS=NTFS LABEL="PARTITION2" QUICK
    assign letter c
    Active
    Exit

    Thanks,
     
    WB, Nov 25, 2008
    #1
    1. Advertisements

  2. I don't know anything about diskpart.exe but you could walk around the
    problem by using this batch file to automate the job.

    @echo off
    echo> diskpart1.scr select disk 0
    echo>>diskpart1.scr list partition
    echo>>diskpart1.scr exit
    diskpart < diskpart1.scr | findstr /i "primary logical" > diskpart.txt

    echo>diskpart2.scr select disk 0 > diskpart2.scr
    for /F "tokens=1,2" %%a in (diskpart.txt) do (
    echo>>diskpart2.scr %%a %%b
    echo>>diskpart2.scr delete partition noerr
    )

    echo>>diskpart2.scr select disk 0
    echo>>diskpart2.scr create partition primary size 2000
    echo>>diskpart2.scr format FS=FAT LABEL="PARTITION1" QUICK
    echo>>diskpart2.scr assign letter d
    echo>>diskpart2.scr create partition extended
    echo>>diskpart2.scr create partition logical
    echo>>diskpart2.scr format FS=NTFS LABEL="PARTITION2" QUICK
    echo>>diskpart2.scr assign letter c
    echo>>diskpart2.scr Active
    echo>>diskpart2.scr Exit

    diskpart < diskpart2.scr
     
    Pegasus \(MVP\), Nov 25, 2008
    #2
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.