Page 2 of 2

Re: HB_Dirscan with filemask

Posted: Mon Mar 16, 2020 8:13 am
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:

Re: HB_Dirscan with filemask

Posted: Mon Mar 16, 2020 9:34 am
by mustafa
Hi Jimmy
View Post by Clip2Mania --> Dirselect.zip
https://www.hmgforum.com/viewtopic.php?f ... HB_DirScan

Regards / Saludos
Mustafa

Re: HB_Dirscan with filemask

Posted: Mon Mar 16, 2020 3:16 pm
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() )


Re: HB_Dirscan with filemask

Posted: Tue Mar 17, 2020 12:38 am
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