Link to home
Start Free TrialLog in
Avatar of bretthonn13
bretthonn13

asked on

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.  
Avatar of sirbounty
sirbounty
Flag of United States of America image

format e: /q /u /v:Label
..where Label is the label name you want to assign it...
Avatar of bretthonn13
bretthonn13

ASKER

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

format e: /q /u /v:MyLabel
for instance...
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.
Hm..

what about

echo myLabel | format e: /v /u
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.
how about

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

echo myLabel | format e: /u /v:
with the /q in there too, if you needed it quickformatted
it still just gets me right back to my prompt.  that is a pipe symbol between the label and format, correct?
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
sorry, no luck.  
Hmm - I don't have a drive to test - but is this because it's ntfs?
It is NTFS for sure.  Do you think that could be the problem?  
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
"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!
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

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
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 . . .
ASKER CERTIFIED SOLUTION
Avatar of sirbounty
sirbounty
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hooray! (was beginning to think I was just getting 'old' - haha!)
Happy to have helped...glad it worked for you.
Thanx for the grade! :^)