Format external drive in using DOS commands in C program

I want to format an external hard drive using a DOS command.  The OS is Win 2003.  The drive letter is 'e:' .  When I try the following syntax I get: "Enter Current Volume Label for Drive E:".

format e: /q /u

I want to do this in a program so I can't have it asking me to enter more data.  We run a C program for a backup strategy and I want to format each external drive before we backup daily.  
bretthonn13Asked:
Who is Participating?
 
sirbountyConnect With a Mentor Commented:
Wow...things have changed since I did this last... : (
That's a lot of prompts to account for, huh?
Try placing a /y at the end of the format command...format e: /x /q /u /v:NewVolume /y
0
 
sirbountyCommented:
format e: /q /u /v:Label
0
 
sirbountyCommented:
..where Label is the label name you want to assign it...
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
bretthonn13Author Commented:
nope, it still prompts me to "Enter current volume label for drive E:"
0
 
sirbountyCommented:
You'll need to change the Label above to something though...did you do this?

format e: /q /u /v:MyLabel
for instance...
0
 
bretthonn13Author Commented:
sirbounty

yep, it acts as though it doesn't even see that last parameter.  as soon as I type the real label it fires off no problem.
0
 
sirbountyCommented:
Hm..

what about

echo myLabel | format e: /v /u
0
 
bretthonn13Author Commented:
we're getting somewhere.  It then prompts me twice asking tif I wish to proceed with format and then imediately goes to the original command prompt.
0
 
sirbountyCommented:
how about

echo MyLabel | form e: /v /u /L:
0
 
sirbountyCommented:
sorry, that should've read

echo myLabel | format e: /u /v:
0
 
sirbountyCommented:
with the /q in there too, if you needed it quickformatted
0
 
bretthonn13Author Commented:
it still just gets me right back to my prompt.  that is a pipe symbol between the label and format, correct?
0
 
sirbountyCommented:
yes sir.
I wonder if it's due to the unconditional parameter?
try

format e: /q /v:myLabel
or
echo mYLabel | format e: /q /v
0
 
bretthonn13Author Commented:
sorry, no luck.  
0
 
sirbountyCommented:
Hmm - I don't have a drive to test - but is this because it's ntfs?
0
 
bretthonn13Author Commented:
It is NTFS for sure.  Do you think that could be the problem?  
0
 
sirbountyCommented:
Ah - I think I know the problem...it's asking for you to verify the current volume label perhaps?

How about this? (does it 'have' to be all one line, or just scripted?)

for /f "tokens=6*" %%a in ('vol e:^|find /i "drive"') do set volname=%%a
echo %volName%|format e: /x /q /u /v:myLabel
0
 
sirbountyCommented:
"Enter Current Volume Label for Drive E:".
is a safeguard against formatting the wrong disk...(supposedly) - so it's asking you to confirm that you know what you're doing basically..

I "think" the above will do it...let me know!
0
 
bretthonn13Author Commented:
I was doing it in a DOS window so I thought it had to be all on one line???  where do you suggest I put these lines:
for /f "tokens=6*" %%a in ('vol e:^|find /i "drive"') do set volname=%%a
echo %volName%|format e: /x /q /u /v:myLabel

0
 
sirbountyCommented:
save them (notepad will work) into a single file,
formatmydrive.bat (or something more clever :) - just don't call it format.bat...format's already taken...haha
0
 
bretthonn13Author Commented:
this is exactly what I typed in my "clever" .bat file....

for /f "tokens=6*" %%a in ('vol e:^|find /i "drive"') do set volname=%%a
echo %volName%|format e: /x /q /u /v:extDRV
PAUSE

...and this is what I get in my comman window:


C:\Documents and Settings\Brett\Desktop>for /F "tokens=6*" %a in ('vol e:|find /
i "drive"') do set volname=%a

C:\Documents and Settings\Brett\Desktop>set volname=extDRV

C:\Documents and Settings\Brett\Desktop>echo extDRV  | format e: /x /q /u /v:ext
DRV
The type of the file system is NTFS.
Enter current volume label for drive E:
WARNING, ALL DATA ON NON-REMOVABLE DISK
DRIVE E: WILL BE LOST!
Proceed with Format (Y/N)?
WARNING, ALL DATA ON NON-REMOVABLE DISK
DRIVE E: WILL BE LOST!
Proceed with Format (Y/N)?
C:\Documents and Settings\Brett\Desktop>PAUSE
Press any key to continue . . .
0
 
sirbountyCommented:
Hooray! (was beginning to think I was just getting 'old' - haha!)
Happy to have helped...glad it worked for you.
Thanx for the grade! :^)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.