#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
karinha wrote:Master Enrico, HB_DIREXISTS() Never worked with xHarbour.
Maestro Enrico, HB_DIREXISTS() Nunca trabajo(Funcionó) en xHarbour.
Regards, saludos.
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
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.
#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
*/
Enrico Maria Giordano wrote:Sorry, I don't understand. Is that the behavior you expected or not?
Return to FiveWin para Harbour/xHarbour
Users browsing this forum: Google [Bot] and 47 guests