Solved

Format external drive in using DOS commands in C program

Posted on 2007-03-26
22
250 Views
Last Modified: 2010-04-03
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.  
0
Comment
Question by:bretthonn13
  • 14
  • 8
22 Comments
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
format e: /q /u /v:Label
0
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
..where Label is the label name you want to assign it...
0
 

Author Comment

by:bretthonn13
Comment Utility
nope, it still prompts me to "Enter current volume label for drive E:"
0
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
You'll need to change the Label above to something though...did you do this?

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

Author Comment

by:bretthonn13
Comment Utility
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
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
Hm..

what about

echo myLabel | format e: /v /u
0
 

Author Comment

by:bretthonn13
Comment Utility
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
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
how about

echo MyLabel | form e: /v /u /L:
0
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
sorry, that should've read

echo myLabel | format e: /u /v:
0
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
with the /q in there too, if you needed it quickformatted
0
 

Author Comment

by:bretthonn13
Comment Utility
it still just gets me right back to my prompt.  that is a pipe symbol between the label and format, correct?
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
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
 

Author Comment

by:bretthonn13
Comment Utility
sorry, no luck.  
0
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
Hmm - I don't have a drive to test - but is this because it's ntfs?
0
 

Author Comment

by:bretthonn13
Comment Utility
It is NTFS for sure.  Do you think that could be the problem?  
0
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
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
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
"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
 

Author Comment

by:bretthonn13
Comment Utility
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
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
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
 

Author Comment

by:bretthonn13
Comment Utility
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
 
LVL 67

Accepted Solution

by:
sirbounty earned 500 total points
Comment Utility
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
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
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

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

The Samsung SSD 840 EVO and 840 EVO mSATA have a well-known problem with a drop in read performance. I first learned about this in an interesting thread here at Experts Exchange: http://www.experts-exchange.com/Hardware/Storage/Hard_Drives/Q_2852…
The article will include the best Data Recovery Tools along with their Features, Capabilities, and their Download Links. Hope you’ll enjoy it and will choose the one as required by you.
This tutorial will walk an individual through the process of installing the necessary services and then configuring a Windows Server 2012 system as an iSCSI target. To install the necessary roles, go to Server Manager, and select Add Roles and Featu…
This Micro Tutorial will teach you how to reformat your flash drive. Sometimes your flash drive may have issues carrying files so this will completely restore it to manufacturing settings. Make sure to backup all files before reformatting. This w…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now