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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Check if floppy is in drive 1

Status
Not open for further replies.

INFORMAT

Programmer
Jan 3, 2001
121
BE
Hi,

I want to check, in a easy way, if there is a floppy in the drive.

Thanks,
>:):O>

 
This is actual a routine to check to seek if a disk is writeprotected, but should work just as well for check drive A:

*:*****************************************************************************
*:
*: Function: checkmediawrite
*:
*:*****************************************************************************
FUNCTION CheckMediaWrite()
PARAMETERS lsDrive

*-- Defines from Winbase.h
#DEFINE SEM_FAILCRITICALERRORS 0x0001
#DEFINE SEM_NOGPFAULTERRORBOX 0x0002
#DEFINE SEM_NOALIGNMENTFAULTEXCEPT 0x0004
#DEFINE SEM_NOOPENFILEERRORBOX 0x8000

*-- Check that the PARAMETERS is in the correct format.
IF SUBSTR(lsDrive, 2, 1) <> &quot;:&quot; OR ;
(ASC(UPPER(SUBSTR(lsDrive, 1, 1))) < 65 OR ;
ASC(UPPER(SUBSTR(lsDrive, 1, 1))) > 90)
=MESSAGEBOX(&quot;Drive must be in the format <drive letter>:&quot;, ;
0, &quot;Error&quot;)
RETURN -1
ENDIF

*-- SetErrorMode determines whether the system handles
*-- serious errors or whether the program handles them.
DECLARE INTEGER SetErrorMode IN win32api INTEGER

*-- SetErrorMode returns to what the flags were last set.
*-- You need to store this in lnResult so that you can set them
*-- back the way they were before calling SetErrorMode.
*-- Failure to do so can produce unpredictable results
*-- when encountering future errors. SetErrorMode only
*-- applies to the current process and therefore only affects
*-- the FoxPro program that called SetErrorMode.
lnResult = SetErrorMode(SEM_FAILCRITICALERRORS)

hFile = FCREATE(lsDrive + &quot;\tmp.txt&quot;)
IF hFile <> -1
FCLOSE(hFile)
ERASE(lsDrive + &quot;\tmp.txt&quot;)
hFile=.T.
ELSE
hFile=.F.
ENDIF

*-- Put things back the way you found them.
lnResult = SetErrorMode(lnResult)

RETURN hFile
*-- Code ends here.
 
INFORMAT

Following code comes from an application, so will need modification as it is checking all drives and updating a table.

lcCurrentDir = SYS(5) + CURDIR() && Current folder

ON ERROR lValidDrive = .F.
lValidDrive = .T.

FOR lnDrive = 65 TO 90 && Drives A - Z
[tab]lcDrive = CHR(lnDrive)

[tab]SET DEFA TO (lcDrive) && Attempt to logon to drive

[tab]IF lValidDrive
[tab][tab]INSERT INTO DRIVES (drive, checked);
[tab][tab][tab]VALUES (lcDrive + [:\],.T.)
[tab]ENDIF

[tab]lValidDrive = .T.
ENDFOR

GO TOP IN DRIVES

ON ERROR

SET DEFA TO &lcCurrentDir

Chris :)
 
You can try:

noFloppy=diskspace('a:')
if noFloppy<0
messagebox('No disk in floppy drive')
endif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top