Function Hb_DirExists() no permite File() ubique los archivo

Function Hb_DirExists() no permite File() ubique los archivo

Postby CARLOS ATUNCAR » Tue Oct 31, 2023 10:35 pm

Saludos luego de recibir problemas con la nueva version FWH2307 en la migración encontre la causa el problema al usar la funcion Hb_DirExists() la funcion File() no reconosca los archivo que estan en la misma carpeta salvo se coloque la ruta completa
estoy usando la ultima compilacion del xharbour.

Gracias
CARLOS ATUNCAR
 
Posts: 117
Joined: Thu Sep 17, 2015 11:40 pm

Re: Function Hb_DirExists() no permite File() ubique los archivo

Postby paquitohm » Wed Nov 01, 2023 9:12 am

Hola,

Pues la verdad es que he leído varias veces el msg y no entiendo lo que quiere decir. Igual un ejemplo de codigo puede ayudar

Salu2
paquitohm
 
Posts: 108
Joined: Fri Jan 14, 2022 8:37 am


Re: Function Hb_DirExists() no permite File() ubique los archivo

Postby nageswaragunupudi » Wed Nov 01, 2023 5:34 pm

There is a bug in hb_DirExists()
Fixed in the new version FWH2310 to be released very soon
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10248
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Function Hb_DirExists() no permite File() ubique los archivo

Postby Enrico Maria Giordano » Wed Nov 01, 2023 6:13 pm

Rao, as far as I know, xHarbour already have a working HB_DIREXISTS() function. To fix FWH you only have to remove this code from harbour.prg:

Code: Select all  Expand view
#ifndef __XHARBOUR__

// to be used with Harbour 3.4
// function hb_HSetCaseMatch( ... )
// return hb_HCaseMatch( ... )

#else

function hb_DirExists( cDirName )

//   local cDir := CurDir(), lExists := .F.
   local cDir := CurDrive() + ":\" + CurDir(), lExists := .F.

   if DirChange( cDirName ) == 0
      lExists = .T.
      DirChange( cDir )
   endif

return lExists

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

Re: Function Hb_DirExists() no permite File() ubique los archivo

Postby karinha » Wed Nov 01, 2023 6:45 pm

Master Enrico, HB_DIREXISTS() Never worked with xHarbour.

Maestro Enrico, HB_DIREXISTS() Nunca trabajo(Funcionó) en xHarbour.


Regards, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7214
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: Function Hb_DirExists() no permite File() ubique los archivo

Postby nageswaragunupudi » Wed Nov 01, 2023 6:46 pm

Mr. Enrico

Thanks.
This function was written many years back in harbour.prg of FWH, when this function was not existing in xHarbour.
Yes the recent versions of xHarbour have this function.
We'll go by your advice.

ps: done. removed
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10248
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Function Hb_DirExists() no permite File() ubique los archivo

Postby Enrico Maria Giordano » Wed Nov 01, 2023 8:24 pm

karinha wrote:Master Enrico, HB_DIREXISTS() Never worked with xHarbour.

Maestro Enrico, HB_DIREXISTS() Nunca trabajo(Funcionó) en xHarbour.


Regards, saludos.


Please, provide a sample demonstrating the problem. You can't use FWH but pure xHarbour console. Otherwise you are using the FWH modified function and not the xHarbour native one.
User avatar
Enrico Maria Giordano
 
Posts: 8315
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Function Hb_DirExists() no permite File() ubique los archivo

Postby Enrico Maria Giordano » Wed Nov 01, 2023 8:26 pm

nageswaragunupudi wrote:Mr. Enrico

Thanks.
This function was written many years back in harbour.prg of FWH, when this function was not existing in xHarbour.
Yes the recent versions of xHarbour have this function.
We'll go by your advice.

ps: done. removed


Thank you. As far as I read on the changelog, this function is in xHarbour lib since 2008.
User avatar
Enrico Maria Giordano
 
Posts: 8315
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Function Hb_DirExists() no permite File() ubique los archivo

Postby CARLOS ATUNCAR » Thu Nov 02, 2023 3:45 am

He realizado esta prueba en modo consola y si ubica el archivo dentro de la carpeta de samples

#include "fileio.ch"
#define CRLF Chr(13)+Chr(10)

FUNCTION Main()
LOCAL cDir := "C:\Program Files"

IF HB_DirExists(cDir)
?cDir + CRLF + CRLF + If(IsDirWritable(cDir), "You can write in this directory.", "You have not permissions to write in this directory!")
ELSE
?cDir + CRLF + CRLF + "Directory not found!"
ENDIF

IF File("pruebadir.map")
?"Archivo si se encuentra"
EndIf


RETURN NIL

FUNCTION IsDirWritable(cDir)
LOCAL cFileName
LOCAL nFileHandle

nFileHandle := HB_fTempCreate(cDir, NIL, FC_NORMAL, @cFileName)

IF nFileHandle != F_ERROR
fClose(nFileHandle)
fErase(cFileName)
RETURN .T.
ENDIF

RETURN .F.
CARLOS ATUNCAR
 
Posts: 117
Joined: Thu Sep 17, 2015 11:40 pm

Re: Function Hb_DirExists() no permite File() ubique los archivo

Postby Enrico Maria Giordano » Thu Nov 02, 2023 8:08 am

Sorry, I don't understand. Is that the behavior you expected or not?
User avatar
Enrico Maria Giordano
 
Posts: 8315
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Function Hb_DirExists() no permite File() ubique los archivo

Postby karinha » Thu Nov 02, 2023 2:08 pm

Enrico Maria Giordano wrote:
karinha wrote:Master Enrico, HB_DIREXISTS() Never worked with xHarbour.

Maestro Enrico, HB_DIREXISTS() Nunca trabajo(Funcionó) en xHarbour.


Regards, saludos.


Please, provide a sample demonstrating the problem. You can't use FWH but pure xHarbour console. Otherwise you are using the FWH modified function and not the xHarbour native one.


Master Enrico, I don't use CONSOLE MODE. I'm saying that with FiveWin, the command NEVER worked.

Maestro Enrico, no uso el MODO CONSOLA. Lo que digo es que con FiveWin el comando NUNCA funcionó.

Code: Select all  Expand view

#include "FiveWin.ch"
#include "directry.ch"
#include "fileio.ch"


/*
 * hb_DirScan()
 *
 * Copyright 2008 Przemyslaw Czerpak <druzus / at / priv.onet.pl>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2, or (at your option)
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; see the file LICENSE.txt.  If not, write to
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301 USA (or visit https://www.gnu.org/licenses/).
 *
 * As a special exception, the Harbour Project gives permission for
 * additional uses of the text contained in its release of Harbour.
 *
 * The exception is that, if you link the Harbour libraries with other
 * files to produce an executable, this does not by itself cause the
 * resulting executable to be covered by the GNU General Public License.
 * Your use of that executable is in no way restricted on account of
 * linking the Harbour library code into it.
 *
 * This exception does not however invalidate any other reasons why
 * the executable file might be covered by the GNU General Public License.
 *
 * This exception applies only to the code released by the Harbour
 * Project under the name Harbour.  If you copy code from other
 * Harbour Project or Free Software Foundation releases into a copy of
 * Harbour, as the General Public License permits, the exception does
 * not apply to the code that you add in this way.  To avoid misleading
 * anyone as to the status of such modified files, you must delete
 * this exception notice from them.
 *
 * If you write modifications of your own for Harbour, it is your choice
 * whether to permit this exception to apply to your modifications.
 * If you do not wish that, delete this exception notice.
 *
 */


PROC TestDScan()

   LOCAL aFFList := HB_DirScan( "C:\TEMP" )

   LOCAL x1Row

   /*
   FOR EACH x1Row IN aFFList

      ? PAD( x1Row[ 1 ], 23 ), ;                     // Name
        TRAN( x1Row[ 2 ], '999,999,999,999' ), ;     // Size
        x1Row[ 3 ], ;                                // Date
        x1Row[ 4 ], ;                                // Time
        x1Row[ 5 ]                                   // Attributes
   NEXT x1Row
   */


   Xbrowse( HB_DirScan( "C:\TEMP", "TURO04.txt", "A" ) )

RETURN NIL // TestDScan()

STATIC FUNCTION hb_doScan( cPath, cMask, cAttr, cPathSep )

   LOCAL aFile
   LOCAL lMatch
   LOCAL aResult := {}

   FOR EACH aFile IN hb_vfDirectory( cPath + hb_osFileMask(), cAttr + "D" )
      lMatch := hb_FileMatch( aFile[ F_NAME ], cMask )
      IF "D" $ aFile[ F_ATTR ]
         IF lMatch .AND. "D" $ cAttr
            AAdd( aResult, aFile )
         ENDIF
         IF !( aFile[ F_NAME ] == "." .OR. aFile[ F_NAME ] == ".." .OR. aFile[ F_NAME ] == "" )
            AEval( hb_DoScan( cPath + aFile[ F_NAME ] + cPathSep, cMask, cAttr, cPathSep ), ;
               {| x | x[ F_NAME ] := aFile[ F_NAME ] + cPathSep + x[ F_NAME ], ;
               AAdd( aResult, x ) } )
         ENDIF
      ELSEIF lMatch
         AAdd( aResult, aFile )
      ENDIF
   NEXT

RETURN aResult

FUNCTION hb_DirScan( cPath, cFileMask, cAttr )

RETURN hb_DoScan( hb_DirSepAdd( hb_defaultValue( cPath, "" ) ),    ;
       iif( HB_ISSTRING( cFileMask ), cFileMask, hb_osFileMask() ), ;
       hb_defaultValue( cAttr, "" ), ;
       hb_ps() )

FUNCTION hb_DirRemoveAll( cDir )

   LOCAL aFile, cPath, cFile, nAttr

   IF ! Empty( cDir ) .AND. hb_vfDirExists( cDir )
      cPath := hb_DirSepDel( cDir )
      IF hb_vfAttrGet( cPath, @nAttr ) .AND. ! hb_bitAnd( nAttr, HB_FA_READONLY ) == 0
         hb_vfAttrSet( cPath, hb_bitXor( nAttr, HB_FA_READONLY ) )
      ENDIF
      cPath := hb_DirSepAdd( cPath )
      FOR EACH aFile IN hb_vfDirectory( cPath + hb_osFileMask(), "HSDL" )
         IF "D" $ aFile[ F_ATTR ] .AND. ! "L" $ aFile[ F_ATTR ]
            IF !( aFile[ F_NAME ] == "." .OR. aFile[ F_NAME ] == ".." .OR. aFile[ F_NAME ] == "" )
               IF ! hb_DirRemoveAll( cPath + aFile[ F_NAME ] )
                  RETURN .F.
               ENDIF
            ENDIF
         ELSE
            cFile := cPath + aFile[ F_NAME ]
            IF "R" $ aFile[ F_ATTR ] .AND. hb_vfAttrGet( cFile, @nAttr )
               hb_vfAttrSet( cFile, hb_bitAnd( nAttr, hb_bitNot( HB_FA_READONLY ) ) )
            ENDIF
            IF ! hb_vfErase( cFile ) == 0
               RETURN .F.
            ENDIF
         ENDIF
      NEXT
      RETURN hb_vfDirRemove( cDir ) == 0
   ENDIF

RETURN .T.

FUNCTION hb_FileDelete( cFileMask, cAttr )

   LOCAL lAny := .F., aFile, cPath, cFile, cAttrMask, nAttr

   IF HB_ISSTRING( cFileMask ) .AND. ! Empty( cFileMask ) .AND. ;
      ! hb_vfDirExists( cFileMask )
      cPath := hb_FNameDir( cFileMask )
      cAttrMask := StrTran( hb_defaultValue( cAttr, "" ), "D" ) + "L"
      FOR EACH aFile IN hb_vfDirectory( cFileMask, cAttrMask )
         cFile := cPath + aFile[ F_NAME ]
         IF "R" $ aFile[ F_ATTR ] .AND. hb_vfAttrGet( cFile, @nAttr )
            hb_vfAttrSet( cFile, hb_bitAnd( nAttr, hb_bitNot( HB_FA_READONLY ) ) )
         ENDIF
         IF hb_vfErase( cFile ) == 0
            lAny := .T.
         ENDIF
      NEXT
   ENDIF

RETURN lAny

/*
HB_DirScan

Scan a directory tree and build a files and folders list

Syntax:
*/


//    HB_DirScan( <cPath>, <cFileMask>, <cAttributes> ) --> <aDirsAndFiles>

/*
Arguments

<cPath> : A character string holding the drive, directory and/or file specification to retrieve information for. Default is current directory.

<cFileMask> ( skeleton > : For filter files to add to the list, (can include wild card characters). Default is ‘*.*’.

<cAttributes> : A character string holding file attributes can be specified. Information about files carrying these attributes is retrieved. One or more characters of the table below can be included in <cAttributes>. For add directories to the list add ‘D’ to <cAttributes>.

Attributes for HB_DirScan() :

         Attribute Meaning
         --------- -------------------------
             A     Archive
             D     Directories
             H     Hidden files
             R     Read-only
             S     System files
Returns

<aDirsAndFiles> : A two-dimensional array of five columns; holding information about files in the <cPath> and the that match <cFileMask>. An empty array, if no matched file found or an error occured.

Description

The HB_DirScan() function is similair to the Directory(). The first difference is that HB_DirScan() scans recursively all sub- directories in the directory specified with <cPath>. And second difference is Directory() don’t requires <cFileMask> parameter, instead this info included in the <cPath>.

The result is a two dimensional array . Columns can be accessed using #define constants from the DIRECTRY.CH file.

Constants for the HB_DirScan() array :

         Symbolic Numeric
         Constant Value  Meaning             Data Type
         -------- -----  ------------------- --------------
         F_NAME     1    File name           Character
         F_SIZE     2    File size in bytes  Numeric
         F_DATE     3    File date           Date
         F_TIME     4    File time           Character
         F_ATTR     5    File attributes     Character
*/


/*
Files

Header: Directry.ch
Example

      Assuming this directory tree and files exist :

      C:\
         | temp                     D
         + ---- + Dir1              D
                |      doc1.docx    F
                |      test1.bat    F
                |      test1.txt    F
                + Dir2              D
                |      doc2.docx    F
                |      test2.bat    F
                |      test2.txt    F
                + run.bat           F
                  test.bat          F
                  test.exe          F

      PROC TestDScan()

         LOCAL aFFList := HB_DirScan( "C:\TEMP" )

         LOCAL x1Row

         FOR EACH x1Row IN aFFList
            ? PAD( x1Row[ 1 ], 23 ),;                     // Name
              TRAN( x1Row[ 2 ], '999,999,999,999' ),;     // Size
              x1Row[ 3 ],;                                // Date
              x1Row[ 4 ],;                                // Time
              x1Row[ 5 ]                                  // Attributes
         NEXT x1Row

      RETU // TestDScan()

      Result :

         Dir1\doc1.docx       14,757 26.02.2014 00:04:27 A
         Dir1\test1.bat           54 24.02.2014 00:54:01 A
         Dir1\test1.txt           54 24.02.2014 00:54:01 A
         Dir2\doc2.docx       14,757 26.02.2014 00:04:27 A
         Dir2\test2.bat           54 24.02.2014 00:54:01 A
         Dir2\test2.txt           54 24.02.2014 00:54:01 A
         runDiz.bat               24 27.02.2014 01:12:28 A
         test.bat                 54 24.02.2014 00:54:01 A
         test.exe          1,413,285 27.02.2014 01:10:36 A


      HB_DirScan( "C:\TEMP\*.txt" ) <- Incorrect call !


      HB_DirScan( "C:\TEMP\", "*.txt" )

      Result :

         Dir1\test1.txt           54 24.02.2014 00:54:01 A
         Dir2\test2.txt           54 24.02.2014 00:54:01 A
*/

 


Regards, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7214
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: Function Hb_DirExists() no permite File() ubique los archivo

Postby Enrico Maria Giordano » Thu Nov 02, 2023 2:24 pm

You didn't understand. The function HB_DIREXIXST() of xHarbour works fine but FWH redefined it uncorrectly. Now it should be ok.
User avatar
Enrico Maria Giordano
 
Posts: 8315
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Function Hb_DirExists() no permite File() ubique los archivo

Postby CARLOS ATUNCAR » Thu Nov 02, 2023 2:25 pm

Enrico Maria Giordano wrote:Sorry, I don't understand. Is that the behavior you expected or not?



Si es como deberia trabajar
CARLOS ATUNCAR
 
Posts: 117
Joined: Thu Sep 17, 2015 11:40 pm



Return to FiveWin para Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 77 guests