Bekz.net - (14016 of 825968 - 2%) 

 Home | Tips & Tricks | General Info | Downloads | NG Archive | Links | Email | Search | Register | Users | Login

 


 

Tips & Tricks

 

Rating: 60% (2 votes registred)
Rate this item:

Back to list

Is there a function that returns all available local drives?

Thanks to Tonhino for this great tip! Via wrappers to the API functions acpGetDrives and acpGetDrvType he made FiveWin functions to retrieve all local drives on your machine.

This is how the code looks:

#include "fivewin.ch"
#include "dll.ch"

procedure main()

local x := 1
local aDrv := GetLocalDrives()

for x := 1 to Len( aDrv )
MsgInfo( aDrv[ x ] + " - " + GetDriveType( aDrv[ x ] ) )
next

return

//------------------------//

dll32 static function ;
      AcpGetDrives( nLength AS LONG, ;
                    @cBuffer AS STRING ) ;
      AS LONG PASCAL FROM "GetLogicalDriveStringsA" ;
      LIB "kernel32.dll"

dll32 static function;
      AcpGetDrvType( cDrive AS STRING ) ;
      AS LONG PASCAL FROM "GetDriveTypeA" ;
      LIB "kernel32.dll"

//-------------------------//
function GetLocalDrives()

local nError := 0
local x := 0
local cDrives := Space( 78 )
local aDrives := {}

AcpGetDrives( 78, @cDrives )

for x:= 1 to 78 step 4
if !Empty( StrTran( SubStr( cDrives, x, 3 ), Chr( 0 ), "" ) )
AAdd( aDrives, SubStr( cDrives, x, 3 ) )
endif
next

return aDrives

//-------------------------//

function GetDriveType( cDrive )

local nType := AcpGetDrvType( cDrive )

do case
 case nType == 0 ; cDrive = ""
 case nType == 1 ; cDrive = cDrive + " does not exist"
 case nType == 2 ; cDrive = "Removable Media"
 case nType == 3 ; cDrive = "Hard Drive"
 case nType == 4 ; cDrive = "Network Drive"
 case nType == 5 ; cDrive = "CD ROM Drive"
 case nType == 6 ; cDrive = "RAM Drive"
endcase

return cDrive

 

 

 

 

 

© 2002 Bekz.net, Inc. All Rights Reserved.