Batch file formatting, Diskpart formatting

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Batch file formatting, Diskpart formatting

#16 Post by foxidrive » 19 Feb 2012 19:28

mini-rooter wrote:
for %%a in (a b c d e f g h i j k l m n o p q r s t u v w x y z) do if exist "%%a:\xyz.bin" set drv=%%a:

(caution, i was testing this out on friday, with 2 flash drives in, both had xyz.bin in the root as i was making copies of the data, my drive which i didnt want to format was E: and the one i was formatting was F:, the computer chose E: and i lost some data... nothing i didn't have backed up but be careful! on a double click this will format what drive its in or what drive it finds with a xyz.bin file)


A pedantic point here, but the code above will save the *last* drive letter that it finds with xyz.bin in the root.

So if you have E: and F: with xyz.bin in the root then it will format F: and not E: as you mention above.

mini-rooter
Posts: 9
Joined: 14 Feb 2012 18:58

Re: Batch file formatting, Diskpart formatting

#17 Post by mini-rooter » 23 Feb 2012 17:16

thanks for the reply about the drive letters :) duely noted and to avoid this mis format happening again, either have no copy of xyz.bin or have the batch file look for your format batch file. so the batch will find it self.

for %%a in (a b c d e f g h i j k l m n o p q r s t u v w x y z) do if exist "%%a:\format.bat" set drv=%%a:

if your batch is called format.bat it will find itself and begin to format it.

but if you want to make it an exe, in the batch call your file format.exe because after conversion it will be an exe and work effectively, thanks for all you help and i appreciate your efforts. Here's to secure data :)

But i can't wait for a crypteks USB!!! they look soo cool and double your protection!

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Batch file formatting, Diskpart formatting

#18 Post by foxidrive » 23 Feb 2012 22:40

Don't call it format.bat

Never use the same name as an external or internal command.

Liviu
Expert
Posts: 470
Joined: 13 Jan 2012 21:24

Re: Batch file formatting, Diskpart formatting

#19 Post by Liviu » 24 Feb 2012 01:31

foxidrive wrote:Don't call it format.bat
That's sound advice, of course. Yet, I still don't see what the "use case" is here, other than the OP admittedly formatted one of his own flash drives by mistake in the process ;-) Can't imagine anyone nowadays would run an unknown .bat file from an unknown stick, just out of curiosity. Or that many users would have autorun enabled on any drive, for that matter.

Liviu

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Batch file formatting, Diskpart formatting

#20 Post by foxidrive » 24 Feb 2012 02:00

It was pointed out to the OP that the contents can be unformatted/unerased after a format. He ignored that aspect, so anything else is just a lesson in batch files. :)

I think it's true as you say, autorun is disabled on flash drives in Windows by default now.

Windows XP had a patch pushed out in Windows Update a year or so ago to disable autorun on some media types too.

Post Reply