How to check if a drive exists.
Thanks in advance
Otto
How to check if a drive exists.
Thanks in advance
Otto
Try:
lisDir( cDrive +":\" )
Or, make it into a function:
function isDrive( cDrive )
return lisDir( cDrive +":\")
James
Otto
Sometimes before you want to check network mapped drive you should reconnect to it.
In this situation in Windows I use:
hWINDG:=WinExec('explorer.exe o:',2)
but it opens new window.
Does somebody know how to check that network drive is connected?
Robert,
>Does somebody know how to check that network drive is connected?
Try this:
//--- Is drive ready?
FUNCTION ISREADY( cDrive )
LOCAL cCurPath := CURDRIVE() + ":\" + CURDIR()
LOCAL lReady := LCHDIR( cDrive + "." )
lSuccess:=.f.
IF lReady
LCHDIR( cCurPath )
lSuccess:= .T.
ENDIF
RETURN lSuccess

FUNCTION ISREADY( cDrive )
local cCurPath, lReady, lSuccess := .F.
MsgInfo( CurDrive(), "CurDrive()" )
MsgInfo( CurDir(), "CurDir()" )
cCurpath = CURDRIVE() + ":\" + CURDIR()
MsgInfo( lReady := lChDir( cDrive + "." ), "lChDir()" )
if lReady
MsgInfo( lSuccess := LCHDIR( cCurPath ), "LCHDIR( cCurPath )" )
endif
return lSuccessAntonio, the error comes
if I insert for example msginfo(lCHDir("m:\"). M is no valid drive.
I get also an exception with LIsDir("").
Regards,
Otto
I forgot to mention if I click on abort then the LCHDir is executed correctly.
The program does not fail โ the exception is only a kind of a msgbox I from WINDOWS.
Regards,
Otto
Otto,
> The program does not fail โ the exception is only a kind of a msgbox I from WINDOWS
Is it the screenshot that you have posted previously in this thread ?
If it is not an error, maybe we can bypass it using a technique that I described here recently (C language).
Antonio,
Here is a VB example that checks to see if the drive exists and if it is ready. Maybe this will help.
http://www.freevbcode.com/ShowCode.Asp?ID=70
James
#include "FiveWin.ch"
function Main()
if GetDriveType( "C:\" ) != 1 // the drive exists
if GetDiskFreeSpace( "C:\" ) // the drive is ready
MsgInfo( "the drive is ready" )
endif
else
MsgAlert( "drive not exist" )
endif
return nil
//------------------------------------------------
#pragma BEGINDUMP
#include <windows.h>
#include <hbapi.h>
HB_FUNC( GETDISKFREESPACE ) // cRootPathName, @nSectorsByCluster, @nBytesPerSector,
// @nNumberOfFreeClusters, @nTotalNumberOfClusters --> lResult
{
LPSTR lpRootPathName = hb_parc( 1 );
DWORD SectorsPerCluster;
DWORD BytesPerSector;
DWORD NumberOfFreeClusters;
DWORD TotalNumberOfClusters;
hb_retl( GetDiskFreeSpace( lpRootPathName, &SectorsPerCluster,
&BytesPerSector, &NumberOfFreeClusters,
&TotalNumberOfClusters ) );
hb_stornl( SectorsPerCluster, 2 );
hb_stornl( BytesPerSector, 3 );
hb_stornl( NumberOfFreeClusters, 4 );
hb_stornl( TotalNumberOfClusters, 5 );
}
#pragma ENDDUMP

Hello Antonio,
J:\ in my case is a cardreader. The test for other letters which do not
exist is working.
i found this msg on the internet:
>Here's a tip to save you hunting for the solution to fix this "Windows no disk" problem in Windows XP (UPDATE: a commenter says changing the drive letters works in Vista too), at least if it's to do with your card reader, or CD or DVD drive.
more
#include "FiveWin.ch"
function Main()
if GetDriveType( "C:\" ) != 1 // the drive exists
if GetDiskFreeSpace( "C:\" ) // the drive is ready
MsgInfo( "the drive is ready" )
endif
else
MsgAlert( "drive not exist" )
endif
return nil
//------------------------------------------------
#pragma BEGINDUMP
#include <windows.h>
#include <hbapi.h>
HB_FUNC( GETDISKFREESPACE ) // cRootPathName, @nSectorsByCluster, @nBytesPerSector,
// @nNumberOfFreeClusters, @nTotalNumberOfClusters --> lResult
{
LPSTR lpRootPathName = hb_parc( 1 );
DWORD SectorsPerCluster;
DWORD BytesPerSector;
DWORD NumberOfFreeClusters;
DWORD TotalNumberOfClusters;
__try
{
hb_retl( GetDiskFreeSpace( lpRootPathName, &SectorsPerCluster,
&BytesPerSector, &NumberOfFreeClusters,
&TotalNumberOfClusters ) );
}
__except ( ( hb_retl( FALSE ), TRUE ) )
{}
hb_stornl( SectorsPerCluster, 2 );
hb_stornl( BytesPerSector, 3 );
hb_stornl( NumberOfFreeClusters, 4 );
hb_stornl( TotalNumberOfClusters, 5 );
}
#pragma ENDDUMPAntonio, the result is the same.
Regards,
Otto