Solved

Format external drive in using DOS commands in C program

Posted on 2007-03-26
22
255 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 14
  • 8
22 Comments
 
LVL 67

Expert Comment

by:sirbounty
ID: 18794165
format e: /q /u /v:Label
0
 
LVL 67

Expert Comment

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

Author Comment

by:bretthonn13
ID: 18794211
nope, it still prompts me to "Enter current volume label for drive E:"
0
Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

 
LVL 67

Expert Comment

by:sirbounty
ID: 18794369
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
ID: 18794406
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
ID: 18794416
Hm..

what about

echo myLabel | format e: /v /u
0
 

Author Comment

by:bretthonn13
ID: 18794465
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
ID: 18794484
how about

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

Expert Comment

by:sirbounty
ID: 18794491
sorry, that should've read

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

Expert Comment

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

Author Comment

by:bretthonn13
ID: 18794902
it still just gets me right back to my prompt.  that is a pipe symbol between the label and format, correct?
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18794912
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
ID: 18794999
sorry, no luck.  
0
 
LVL 67

Expert Comment

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

Author Comment

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

Expert Comment

by:sirbounty
ID: 18795185
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
ID: 18795191
"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
ID: 18795255
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
ID: 18795300
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
ID: 18795349
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
ID: 18796217
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
ID: 18799780
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to update Firmware and Bios in Dell Equalogic PS6000 Arrays and Hard Disks firmware update.
This article is an update and follow-up of my previous article:   Storage 101: common concepts in the IT enterprise storage This time, I expand on more frequently used storage concepts.
This video Micro Tutorial explains how to clone a hard drive using a commercial software product for Windows systems called Casper from Future Systems Solutions (FSS). Cloning makes an exact, complete copy of one hard disk drive (HDD) onto another d…
This video teaches viewers how to encrypt an external drive that requires a password to read and edit the drive. All tasks are done in Disk Utility. Plug in the external drive you wish to encrypt: Make sure all previous data on the drive has been …

724 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