How to check if a drive exists

Re: How to check if a drive exists

Postby FiveWiDi » 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 24.02 + Harbour 3.2.0dev (r2403071241), BCC 7.7 Windows 10
FiveWiDi
 
Posts: 1139
Joined: Mon Oct 10, 2005 2:38 pm

Re: How to check if a drive exists

Postby Enrico Maria Giordano » Wed Jun 09, 2010 6:41 am

Are you using Harbour or xHarbour?

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8600
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: How to check if a drive exists

Postby FiveWiDi » 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 24.02 + Harbour 3.2.0dev (r2403071241), BCC 7.7 Windows 10
FiveWiDi
 
Posts: 1139
Joined: Mon Oct 10, 2005 2:38 pm

Re: How to check if a drive exists

Postby Enrico Maria Giordano » Wed Jun 09, 2010 10:58 am

It's too old. Try using

Code: Select all  Expand view
#pragma BEGINDUMP

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

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

#pragma ENDDUMP


EMG
User avatar
Enrico Maria Giordano
 
Posts: 8600
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: How to check if a drive exists

Postby FiveWiDi » Sun Aug 22, 2010 6: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: Select all  Expand view
/* *************************** */

#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 24.02 + Harbour 3.2.0dev (r2403071241), BCC 7.7 Windows 10
FiveWiDi
 
Posts: 1139
Joined: Mon Oct 10, 2005 2:38 pm

Re: How to check if a drive exists

Postby codemaker » Tue Dec 01, 2015 9:36 pm

Seems that Windows 8 has different logic:

Code: Select all  Expand view

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) ?
User avatar
codemaker
 
Posts: 208
Joined: Wed Dec 03, 2008 4:48 pm
Location: Belgrade, Serbia


Previous

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 31 guests