/* *************************** */
FUNCTION cSelectUSB( lMensaje )
Local aDriveUSB := {}
Local nDriveUSB := 0
Local cDriveUSB := ""
Local nContador := 0
aDriveUSB := aUSBDrive()
If Len( aDriveUSB ) = 0
聽 聽 If lMensaje
聽 聽 聽 聽 MsgAlert( GetTrad("No hi han unitats USB disponibles, insereixi una unitat USB."), GetTrad("A T E N C I 脫 !" ) )
聽 聽 EndIf
聽 Else
聽 聽 nDriveUSB := MsgList( aDriveUSB, GetTrad("Unitats USB disponibles:"), Nil, Nil, Nil, 15, "Seleccionar", nDriveUSB, .T., Nil )
聽 聽 //Traza( 1, nDriveUSB := MsgList( aDriveUSB, GetTrad("Unitats USB disponibles:"), Nil, Nil, Nil, 15, "Seleccionar", nDriveUSB, .T., Nil ) )
聽 聽 If nDriveUSB > 0
聽 聽 聽 聽 cDriveUSB := SubStr( aDriveUSB[ nDriveUSB ], 1, 3 )
聽 聽
聽 聽 聽 聽 //Traza(1, "aDriveUSB[ nDriveUSB ]=", aDriveUSB[ nDriveUSB ])
聽 聽 EndIf
聽 聽
EndIf
//Traza(1, "cDriveUSB=", cDriveUSB)
Return cDriveUSB
/* *************************** */
/* ************************************
聽 聽Torna una array dels USB connectats.
聽 聽--------------------------------- */
#define DRIVE_REMOVABLE 聽2
STATIC FUNCTION aUSBDrive()
Local nBitDrives := GetLogicalDrives()
Local nContador 聽:= 0
Local cDrive 聽 聽 := ""
Local aDrives 聽 聽:= {}
For nContador := 1 to 32
聽 聽 If lAnd( nBitDrives, 2 ^ ( nContador - 1 ) )
聽 聽 聽 聽 cDrive = Chr( Asc( "A" ) - 1 + nContador ) + ":\"
聽 聽 聽 聽 If nContador != 1 .and. GetDriveType( cDrive ) == DRIVE_REMOVABLE
聽 聽 聽 聽 聽 聽 If lExistUSB( cDrive )
聽 聽 聽 聽 聽 聽 聽 聽 AAdd( aDrives, cDrive )
聽 聽 聽 聽 聽 聽 EndIf
聽 聽 聽 聽 Endif
聽 聽 Endif
Next
Return aDrives
/* *************************** */
/* *************************** */
FUNCTION lExistUSB( cDisk )
/* Se da el caso de que con un PenDrive (al menos el que yo he usado) las
funciones IsDisk() y lIsDir() dan .F..
Cuando se trata de una tarjeta de memoria (por ejemplo XD) insertada en
un lector de tarjetas externo conectado a un puerto USB, la IsDisk() sigue
dando .F. y la lIsDir() da .T..
Como lo que se pretende es poder saber que unidades USB son susceptibles de
usarse independientemente de PenDrive o tarjetas de memoria, se opta por
la funci贸n GetDiskFreeSpace() que da .T. tanto para PenDrive como para
tarjetas de memoria.
22/08/2010
*/
Local lExist 聽 聽 聽 聽:= .F.
Local nSetErrorMode := 0
//Traza( 1, "cDisk=", cDisk )
//Traza( 1, "1-SETERRORMODE=", SETERRORMODE() )
nSetErrorMode := SETERRORMODE( 1 )
//Traza( 1, "1-nSetErrorMode=", nSetErrorMode )
//lExist := IsDisk( Left( cDisk, 1) + ":" )
//Traza( 1, "1-lExist=", lExist )
//lExist := lIsDir( Left( cDisk, 1) + ":\" )
//Traza( 1, "2-lExist=", lExist )
lExist := GetDiskFreeSpace( Left( cDisk, 1) + ":\" )
//Traza( 1, "3-lExist=", lExist )
nSetErrorMode := SETERRORMODE( nSetErrorMode )
//Traza( 1, "2-nSetErrorMode=", nSetErrorMode )
//Traza( 1, "2-SETERRORMODE=", SETERRORMODE() )
Return lExist
/* *************************** */#pragma BEGINDUMP
#include "hbapi.h"
#include "windows.h"
HB_FUNC( SETERRORMODE )
{
聽 聽hb_retni( SetErrorMode( hb_parni( 1 ) ) ) ;
}
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