none
batch script "the syntax of the command is incorrect RRS feed

  • General discussion

  • Hi, I am trying t write a batch script that I can use to format a bunch of drives quickly.  It takes input from a user as to what drive to format, then creates a script for diskpart to run everything automatically, but it keeps coming up with a syntax error. here is the code:

    @echo off
    diskpart /s listdisk.txt
    set /p disc="Please select the disk to format:  "
    IF not exist "%USERPROFILE%\Documents\erase%disc%.txt"(
    echo creating script
    echo select disk %disc% > "%USERPROFILE%\Documents\erase%disc%.txt"
    echo clean >> "%USERPROFILE%\Documents\erase%disc%.txt"
    echo create partition primary >> "%USERPROFILE%\Documents\erase%disc%.txt"
    echo format quick fs=fat32 >> "%USERPROFILE%\Documents\erase%disc%.txt"
    echo assign letter="F" >> "%USERPROFILE%\Documents\erase%disc%.txt"
    echo FORMATTING DISK %disc%
    diskpart /s "%USERPROFILE%\Documents\erase%disc%.txt"
    )
    else(
    echo FORMATTING DISK %disc%
    diskpart /s "%USERPROFILE%\Documents\erase%disc%.txt"
    )

    • Changed type Bill_Stewart Friday, July 27, 2018 6:39 PM
    • Moved by Bill_Stewart Friday, July 27, 2018 6:40 PM Unanswerable drive-by question
    Thursday, May 3, 2018 6:53 PM

All replies

  • "but it keeps coming up with a syntax error". Can you be more specific?

    Remember: Nobody can see your screen. What are you entering at the prompt? What is the error message? What troubleshooting steps have you tried so far?


    -- Bill Stewart [Bill_Stewart]

    Thursday, May 3, 2018 7:00 PM
  • What is wrong with just using a simple "format" command.  DISKPART is not necessary here.


    \_(ツ)_/

    Thursday, May 3, 2018 7:03 PM
  • PowerShell can do this better and easier with no need for creating script files. 

    help partition


    \_(ツ)_/

    Thursday, May 3, 2018 7:05 PM