How to check if a drive exists
Posted: Mon Mar 31, 2008 5:51 pm
How to check if a drive exists.
Thanks in advance
Otto
Thanks in advance
Otto
www.FiveTechSoft.com
https://forums.fivetechsoft.com/
Code: Select all
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 lSuccess
Code: Select all
#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
Code: Select all
#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 ENDDUMP