Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Formatting USB Drive

Status
Not open for further replies.

Ed Andres

IS-IT--Management
Mar 27, 2001
142
US
Ok, this seems so simple yet the solution escapes me. I need to be able to format a USB drive prior to writing data to it to make sure it is the right file structure. If I use this line in the command prompt, it always asks me to press enter to continue; FORMAT F: /V:VOL /FS:FAT32 /Q

I have found excellent ideas in the FAQ's to run this line so it is not visible to VFP or the user but, it doesn't seem to work. I suspect it is because of the press enter prompt.

This is what I am using to run a line from the command prompt:
FUNCTION winexecrun
PARAMETER cCommand
DECLARE INTEGER WinExec IN win32api ;
STRING command, INTEGER param
retval = WinExec(SYS(2004) + "FOXRUN.PIF /C " + cCommand, 0)
CLEAR DLLS WinExec
RETURN retval

This is how I am calling it:
cCommand = "FORMAT F: /V:VOL /FS:FAT32 /X"
?winexecrun(cCommand)

The function works with other command lines like in the FAQ.

Any suggestions?

Ed
 
Try this
Create a txt file with the leter Y (Nothing else, just the letter "Y") in it call it y.txt
Pipe the txt file as the answer to the prompt into the command line

cCommand = "FORMAT F: /V:VOL /FS:FAT32 /X < y.txt"

Make sure you create the file where DOS can find it
of add the directory to it

cCommand = "FORMAT F: /V:VOL /FS:FAT32 /X < c:\common\y.txt"


David W. Grewe (Dave)
 
Thanks for the quick reply!
However, your suggestion doen not seem to help.

Maybe there is another way??

Ed
 
Ok, after further review, David, your solution does work. I had a syntax (fat finger) problem with the line.

Baltman, where exactly would you put the chr(10)? In the function or tacked on the end of the variable?

Thanks for your help!

Ed
 
Ed,

This is totally off the top of my head, and I have no intention of testing it, but you might like to try something like this:

Code:
osh = CREATEOBJECT("wscript.shell")
osh.Run("FORMAT F: /V:VOL /FS:FAT32 /X")
osh.AppActivate("??")
osh.SendKeys("Y")

where "??" is the title of the window that pops up after the second line.

If you do decide to try it, do so carefully. I'd hate to hear that I had just formatted your main hard drive <g>.

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Mike,
Guess I have more guts then brains.
LOL, I actually error tested my Answer before I posted it.



David W. Grewe (Dave)
 
Hmmm, I doubt somebody here has more brains than Mike.
But did you really want to try such a command :)
This is ALSO not tested:
Code:
MyFormat([A:\])

FUNCTION MyFormat(lcDrive)
IF NOT INLIST(DRIVETYPE(LEFT(lcDrive,1)), 2, 6)
   RETURN .f.
ENDIF
LOCAL lnDriveNumber
Declare INTEGER SHFormatDrive IN WIN32API INTEGER hwnd,;
                                          INTEGER Drive,;
                                          INTEGER fmtID,;
                                          INTEGER options



   lnDriveNumber = ASC(LEFT(lcDrive,1)) - 65
   SHFormatDrive(_screen.HWnd, lnDriveNumber, 0,0_
RETURN .t.

Borislav Borissov
VFP9 SP1, SQL Server 2000/2005.
MVP VFP
 
Hmm, last line shout be:
Code:
SHFormatDrive(_screen.HWnd, lnDriveNumber, 0, 0)

Borislav Borissov
VFP9 SP1, SQL Server 2000/2005.
MVP VFP
 
Borislav,
I saw a similar bit of code on MSDN site but it appears that it opens the format dialog and requires user interaction. I have not tried it but do not want the user to have to do anything after defining the usb drive letter.

Mike,
I tried your code but "Y" did not work. If you used chr(13) it did work but it popped several more windows to format. That is a little scary not knowing what exactly the other format windows are for.

For now I will go with David's suggestion. This way I can exclude drive C & D and the user won't see a thing. Thanks for your help and speedy repiles. This forum and the members are the best.

Ed
 
Ed,

Now you mention it, I remember that you need to press Enter after typing the Y, which is why you would need to add the CHR(13).

But by all means go with David's idea. Mine was a very much a shot in the dark.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Dave,
Unfortunately, the /U is not an option for Format. It is not documented nor does it work in my testing.

That is the type of solution I was looking for though!

Thanks

Ed
 
Sorry Dave for the slow response. I did try your line and it works. It appears that the /backup switch is what was needed. I added both the /backup and the /u and it worked. Then removed the /backup and it didn't. Not sure why it works and have never seen that switch before.

The funny thing is that if you do a format /? in Windows XP you don't get either of the switches defined and yet when you use them, they must do something.

Thanks for the help

Ed
 
They are undocumented. I think they both stem from the old days when you could make floppy disk backups. The OS would stretch them across disk, but of course the disks needed to be formatted first. Rather than someone having to "Press enter to continue..." all the time, that switch would be added in the background.


-Dave Summers-
[cheers]
Even more Fox stuff at:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top