HB_Dirscan with filemask

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

User avatar
AUGE_OHR
Posts: 2093
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

Re: HB_Dirscan with filemask

Post by AUGE_OHR »

hi,

i try to find all File with Attribut "A"

Code: Select all

    LOCAL aFFList := HB_DirScanM( "c:\hmg.3.4.4\", {"*.*"}, "A" )
    msgInfo (STR(LEN(aFFlist)) + " Files" )
but it give me all files

Question : how to modify Code to get only "new files" with Attribut "A" :idea:
have fun
Jimmy
User avatar
mustafa
Posts: 1172
Joined: Fri Mar 20, 2009 11:38 am
DBs Used: DBF
Location: Alicante - Spain
Contact:

Re: HB_Dirscan with filemask

Post by mustafa »

Hi Jimmy
View Post by Clip2Mania --> Dirselect.zip
http://www.hmgforum.com/viewtopic.php?f ... HB_DirScan

Regards / Saludos
Mustafa
edk
Posts: 999
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

Re: HB_Dirscan with filemask

Post by edk »

AUGE_OHR wrote: Mon Mar 16, 2020 8:13 am hi,

i try to find all File with Attribut "A"

Code: Select all

    LOCAL aFFList := HB_DirScanM( "c:\hmg.3.4.4\", {"*.*"}, "A" )
    msgInfo (STR(LEN(aFFlist)) + " Files" )
but it give me all files

Question : how to modify Code to get only "new files" with Attribut "A" :idea:
Normally, the Directory() function get files w/o any attrib and/or "Read only" and/or "Archive" + given special HSDV attributes: https://harbour.github.io/doc/clc53.html#directory

My example with filtering ARHSDV attribs:

Code: Select all

#include "hmg.ch"

Function Main()
    
    LOCAL aFFList := HB_DirScanM( "g:\, "*.prg", "a" )

    msgdebug (aFFlist)

RETURN 

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

STATIC FUNCTION hb_doScanM( cPath, aMask, cAttr, cPathSep )

   LOCAL aFile
   LOCAL lMatch
   LOCAL aResult := {}

   FOR EACH aFile IN hb_vfDirectory( cPath + hb_osFileMask(), cAttr + "D" )
      lMatch := .F.
      AEVAL( aMask, { | x | iif( HB_ISSTRING ( x ), lMatch := hb_FileMatch( aFile[ F_NAME ], x ) .OR. lMatch, Nil) } )
      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_DoScanM( cPath + aFile[ F_NAME ] + cPathSep, aMask, cAttr, cPathSep ), ;
               {| x | x[ F_NAME ] := aFile[ F_NAME ] + cPathSep + x[ F_NAME ], ;
               AAdd( aResult, x ) } )
         ENDIF
      ELSEIF lMatch .AND. MatchAttr( cAttr, aFile [ F_ATTR ] )
         AAdd( aResult, aFile )
      ENDIF
   NEXT

   RETURN aResult
   

FUNCTION MatchAttr( cAttr, fAttr )
LOCAL i, lRet:=.F.
IF Empty (cAttr)
	RETURN .T.
ENDIF
FOR i=1 TO Len( cAttr )
	lRet:= lRet .OR. Upper( Substr ( cAttr , i, 1 ) )$Upper( fAttr )
NEXT i
RETURN lRet


FUNCTION hb_DirScanM( cPath, aFileMask, cAttr )
   RETURN hb_DoScanM( hb_DirSepAdd( hb_defaultValue( cPath, "" ) ), ;
      iif( HB_ISARRAY( aFileMask ), aFileMask, iif (HB_ISSTRING( aFileMask ), { aFileMask }, { hb_osFileMask() } ) ), ;
      hb_defaultValue( cAttr, "" ), ;
      hb_ps() )

User avatar
AUGE_OHR
Posts: 2093
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

Re: HB_Dirscan with filemask

Post by AUGE_OHR »

hi,

thx for modify Code which work fine :D

i have modify this line

Code: Select all

      ELSEIF lMatch .AND. MatchAttr( cAttr, aFile [ F_ATTR ] )
into

Code: Select all

      ELSEIF lMatch .AND. MatchAttr( cAttr, aFile [ F_ATTR ] ) .AND. aFile [ F_SIZE ] > 0
while have a lot of *.HBC or *.RC with 0 (Zero) Byte which are not need for Backup
have fun
Jimmy
Post Reply