FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour How to check if a drive exists
Posts: 1445
Joined: Mon Oct 10, 2005 02:38 PM
Re: How to check if a drive exists
Posted: Tue Jun 08, 2010 10:11 PM
Enrico Maria Giordano wrote:It is called WAPI_SETERRORMODE() in Harbour.

EMG


Enrico,

I have this message when i use WAPI_SETERROR() function:

Error: Unresolved external '_HB_FUN_WAPI_SETERRORMODE'

Anybody can help me please.

Thanks in avance.
Carlos G.
No se me da muy bien el ingles. :-)

Un Saludo

Carlos G.



FiveWin 25.12 + Harbour 3.2.0dev (r2502110321), BCC 7.7 Windows 11 Home

Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: How to check if a drive exists
Posted: Wed Jun 09, 2010 06:41 AM

Are you using Harbour or xHarbour?

EMG

Posts: 1445
Joined: Mon Oct 10, 2005 02:38 PM
Re: How to check if a drive exists
Posted: Wed Jun 09, 2010 10:24 AM
Enrico Maria Giordano wrote:Are you using Harbour or xHarbour?
EMG


Harbour 1.1.0dev (Rev.10434) -> 03'2009

Tx.
Carlos G.

Un Saludo

Carlos G.



FiveWin 25.12 + Harbour 3.2.0dev (r2502110321), BCC 7.7 Windows 11 Home

Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: How to check if a drive exists
Posted: Wed Jun 09, 2010 10:58 AM
It's too old. Try using

Code (fw): Select all Collapse
#pragma BEGINDUMP

#include "hbapi.h"
#include "windows.h"

HB_FUNC( SETERRORMODE )
{
   hb_retni( SetErrorMode( hb_parni( 1 ) ) ) ;
}

#pragma ENDDUMP


EMG
Posts: 1445
Joined: Mon Oct 10, 2005 02:38 PM
Re: How to check if a drive exists
Posted: Sun Aug 22, 2010 06:40 PM
Gracias Enrico (si ya se hace mucho tiempo de tu mensaje...)

Finalmente he podido (estoy de vacaciones) probar y codificar vuestras soluciones (la de Antonio también), y así está quedando la función para saber si las unidades USB de un lector de tarjetas estan disponibles o no.

Code (fw): Select all Collapse
/* *************************** */

#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

/* *************************** */
/* *************************** */
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..
Com 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

nSetErrorMode := SETERRORMODE( 1 )
lExist := GetDiskFreeSpace( Left( cDisk, 1) + ":\" )
SETERRORMODE( nSetErrorMode )

Return lExist
/* *************************** */


Un saludo
Carlos G.

Un Saludo

Carlos G.



FiveWin 25.12 + Harbour 3.2.0dev (r2502110321), BCC 7.7 Windows 11 Home

Posts: 208
Joined: Wed Dec 03, 2008 04:48 PM
Re: How to check if a drive exists
Posted: Tue Dec 01, 2015 09:36 PM
Seems that Windows 8 has different logic:

Code (fw): Select all Collapse
FUNCTION GetReadyDrives()
      LOCAL aDrives := {}
      LOCAL nDrive  := 1
      LOCAL nMode   := SetErrorMode(1)

      FOR nDrive := 1 TO 26
         IF IsDisk( Chr( 64 + nDrive ) )
            AAdd( aDrives, Chr( 64 + nDrive ) )
         ENDIF
      NEXT

      SetErrorMode( nMode )
   RETURN aDrives


It works fine with any OS before Windows 8
On windows 8 it doesn't recognize the mapped drive on network
If the drive is mapped as H: on \\Toshiba-pc\c\
the function will show all drives (C and D for example) but not H

Is there any fix for this for Windows 8 (and I am affraid to even think about Windows 10) ?
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: How to check if a drive exists
Posted: Tue Dec 01, 2015 09:55 PM
Boris,

try

Code (fw): Select all Collapse
ADrives()


EMG

Continue the discussion