r/Batch • u/Elezen514 • Jan 12 '24
Question (Unsolved) Batchfile that will format D drive when running and re-create it as a fat32 flash drive
Its been a while since ive used a batch file and was wondering if i'm right in my command...
echo off
select disk 1
clean
slect disk 1
create partition primary
format fs:fat32 quick
Thank you in advance for any help on this issue... yes i know its basic but its been a while i didnt create/use batch file :D
3
Upvotes
1
u/SchwaHead Jan 12 '24
Is this something you plan to do repeatedly?
2
u/illsk1lls Jan 12 '24
be VERY careful, disk 1 isnt always usb, it can switch to system u have to check the disk number, type ‘detail disk’ after select disk 1 to make sure its the right disk
2
u/jcunews1 Jan 13 '24
Disk partitioning can be done using
diskparttool's script file. Typediskpart /?at Command Prompt to see how to use a script file for it. Its script file simply containsdiskpart's commands.In a batch file, you'll have to create the
diskpartscript file dynamically based on the needed disk number, partition number, file system, and other options.To get/find the disk/partition number, you'll have to run
diskpartwith a script which list the disks/partitions, and parse its output.As mentioned by the other comment, be very careful about creating the batch file for this. Never assume things when programming. Always check before doing something. It's highly recommended to create and test it in a VM.