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

Driver a:

Status
Not open for further replies.

kitnba

MIS
Jul 31, 2000
132
HK
How can I check the Driver a: have disk or not?
 
kitnba

*
* isDiskIN( <cDrive> ) --> boolean
*
* Return TRUE if drive <cDrive> is ready.
* e.g:
* IF isDiskIN(&quot;A:&quot;)
* DO backup
* ELSE
* MESSAGEBOX(&quot;Drive not ready&quot;)
* ENDIF
*
* Ricardo Fynn (Montevideo, Uruguay)
* rfynn@cs.com.uy
*
FUNCTION isDiskIN( cDrive )
LOCAL lIsLoaded

cDrive = ALLTRIM(cDrive)
IF LEN(cDrive) > 2 .OR. LEN(cDrive) = 0 .OR. .NOT. ;
[tab]BETWEEN(ASC(UPPER(cDrive)), 65, 90)
[tab]RETURN .F.
ENDIF
IF RIGHT(cDrive,1) # &quot;:&quot;
[tab]cDrive = cDrive + &quot;:&quot;
ENDIF
lIsLoaded = &quot;FOXTOOLS&quot; $ SET(&quot;LIBRARY&quot;)
IF .NOT. lIsLoaded
[tab]SET LIBRARY TO SYS(2004)+&quot;FOXTOOLS.FLL&quot; ADDITIVE
ENDIF
cOldError = ON('error')
ON ERROR lDiskError = .T.
cSetErrMode = regfn(&quot;SetErrorMode&quot;, &quot;I&quot;, &quot;I&quot;)
cOldErrState = callfn(cSetErrMode,1)
lDiskError = .F.
cDrivestate = FILE(cDrive + &quot;\NUL&quot;)
IF .NOT. lDiskError
[tab]IF cDrivestate
[tab][tab]cDriveok = .T.
[tab]ELSE
[tab][tab]cDriveok = .F.
[tab]ENDIF
ELSE
[tab]cDriveok = .F.
ENDIF

IF .NOT. EMPTY(cOldError)
[tab]ON ERROR DO (cOldError)
ELSE
[tab]ON ERROR
ENDIF

cRestErrState = callfn(cSetErrMode,cOldErrState)

IF .NOT. lIsLoaded
[tab]RELEASE LIBRARY SYS(2004)+&quot;FOXTOOLS.FLL&quot;
ENDIF

RETURN cDriveok

ENDFUNC

This is a .prg available from
Chris
 
The quick & simple solution:
Code:
lDriveReady = (DISKSPACE(&quot;A&quot;) != -1)

Drawback: annoying diskdrive noise & possible erratic behaviour under Windows NT

The prev. post is a neater solution.

To give yet another solution (taken from the VFUG newsletters issues September 2000 & November 2000):

Code:
oFSO = CREATEOBJECT(&quot;Scripting.FileSystemObject&quot;)
IF oFSO.DriveExists(&quot;A&quot;)
   oDrive = oFSO.GetDrive(&quot;A&quot;)
   lReady = oDrive.IsReady
ENDIF

Refer to the VFUG newsletters (to be found on their web-page) for more info on the subject)
Diederik Vermeeren
verm1864@exact.nl
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top