HB_Dirscan with filemask

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

ROBROS
Posts: 256
Joined: Thu May 25, 2017 6:30 pm
DBs Used: DBF
Location: D 83071 Stephanskirchen

HB_Dirscan with filemask

Post by ROBROS »

Hi friends,
HB_Dirscan is a powerful function, but I have problems to search for several file types.

Example:
LOCAL aFFList := HB_DirScan( "F:\","*.mkv","*.avi"): lists only mkv-files
LOCAL aFFList := HB_DirScan( "F:\","*.mkv,*.avi" ): lists no files at all, but I get no compiler error

Can anyone show me the right syntax?

TIA
Robert
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 ROBROS
View ----> https://vivaclipper.wordpress.com/2014/ ... b_dirscan/
http://hmgforum.com/viewtopic.php?t=5450

Code: Select all

 
      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
Mustafa
ROBROS
Posts: 256
Joined: Thu May 25, 2017 6:30 pm
DBs Used: DBF
Location: D 83071 Stephanskirchen

Re: HB_Dirscan with filemask

Post by ROBROS »

Hi Mustafa,
thx for your reply.
when I scan for *.avi files, then
HB_DirScan( "F:\", "*avi") (F: is a pendrive) works fine,
but I want to scan for multiple file-types in one pass, lets say I want to scan for *.avi, *.mkv *.mp4 in one pass.
In my question the word "several" was wrong, I mean multiple, sorry for that.

Regards
Robert
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 »

View By edk

viewtopic.php?f=5&t=6188&hilit=HB_DirScan&start=10

Modifie by Mustafa

The New Sample is based on an assumption of a Sub-Folder called "Resource"
with *. * we see all the content of "Resource"

Code: Select all


/*

hb_DirScan (<cPath>, [<cFileMask>], [<cAttr>]) ➜ aFiles)

View ---> by edk->  http://www.hmgforum.com/viewtopic.php?f=5&t=6188&hilit=HB_DirScan&start=10

*/

#include "hmg.ch"
#include "directry.ch"

FUNCTION Main()

Local aFolders, aFiles, cDirName, aAllFiles:={}
Local cStartPath:= HB_Curdrive() +":\"+Rtrim(Curdir() ) + "\"+ "Resource"          

msgbox('Search for files in all "*.*" subfolders of the "' + cStartPath + '"' )

aFolders:=hb_DirScan( cStartPath, "*.*", "D" /* Folders */)    //  "*.bmp"

AEVAL ( aFolders, { |aDir| ( cDirName:=aDir [ F_NAME ], aFiles:=hb_Directory ( cStartPath + cDirName + "\*.*" ), AEVAL ( aFiles, { |aFile| AADD (aAllFiles , cStartPath + cDirName + "\" + aFile [ F_NAME ] ) } ) ) } )

MsgDebug(aFolders)

Return Nil

Very simplified

Code: Select all

#include "hmg.ch"
#include "directry.ch"

FUNCTION Main()

Local cCarpeta := HB_Curdrive() +":\"+Rtrim(Curdir() ) + "\"+ "Resource"     

aFFList := HB_DirScan( cCarpeta,"*.bmp" )    //  "*.*"  <----  All extensions

MsgDebug(aFFList)

Return Nil
Regards
Mustafa
User avatar
dragancesu
Posts: 930
Joined: Mon Jun 24, 2013 11:53 am
DBs Used: DBF, MySQL, Oracle
Location: Subotica, Serbia

Re: HB_Dirscan with filemask

Post by dragancesu »

GetFile ( acFilter , cTitle , cDefaultPath , lMultiSelect , lNoChangeDir , nFilterIndex ) --> SelectedFileName(s)

This is not solution, it's hint, no exapmle for many item in nFilterIndex

https://docs.microsoft.com/en-us/dotnet ... mework-4.8
edk
Posts: 999
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

Re: HB_Dirscan with filemask

Post by edk »

ROBROS wrote: Sun Mar 08, 2020 9:23 pm Hi friends,
HB_Dirscan is a powerful function, but I have problems to search for several file types.

Example:
LOCAL aFFList := HB_DirScan( "F:\","*.mkv","*.avi"): lists only mkv-files
LOCAL aFFList := HB_DirScan( "F:\","*.mkv,*.avi" ): lists no files at all, but I get no compiler error

Can anyone show me the right syntax?

TIA
Robert
You can't do this with standard hb_DirScan() function: There is a oryginal source of hb_DirScan: https://github.com/harbour/core/blob/ma ... irscan.prg

But you can make own function :idea:
My example based on Przemyslaw Czerpak core source of hb_DirScan()

Code: Select all

#include "hmg.ch"

Function Main()

    LOCAL aFFList := HB_DirScanM( "F:\", {"*.mkv","*.avi"} )

    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
         AAdd( aResult, aFile )
      ENDIF
   NEXT

   RETURN aResult

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
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 edk
+ 10
Regards
Mustafa
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,

the Solution from edk is a GREAT xBase Solution :!:

... but what if *.AVI are on different Drive ( Server ) :idea:

as i have many Drive i like to point to a 3-PP Tool which can be use with HMG
http://hmgforum.com/viewtopic.php?f=12&t=6192

@Robert : which "Player" do you use :?:
have fun
Jimmy
ROBROS
Posts: 256
Joined: Thu May 25, 2017 6:30 pm
DBs Used: DBF
Location: D 83071 Stephanskirchen

Re: HB_Dirscan with filemask

Post by ROBROS »

Hi Jimmy,
let me explain what my intention is:
I have a lot of movies on 4 different usb-drives and one (exclusively used for data) internal HDD (1TB). The number of movies is approximate 1000.
Of course, I do not know exactly on which drive a movie is stored and if a certain movie exists on a drive at all. So I will assign a name
to each drive and list all the movies in a single dbf with the name of the drive. So I have one table where all the movies are stored by name.
Now I can do a search for a movie or find redundances.
I want to keep the storage of movies local (no local server,no cloud).
I use vlc with ubuntu 18.04
Regards
Robert
ROBROS
Posts: 256
Joined: Thu May 25, 2017 6:30 pm
DBs Used: DBF
Location: D 83071 Stephanskirchen

Re: HB_Dirscan with filemask

Post by ROBROS »

Hi friends,
edk's proposal is a bit too high for me, at least so far I did not find out how a codeblock really works, but I surely will.
Until that day in the future ;-) I found another solution for my problem. I found it in friend esgici's collection "vivaclipper":
It is the function HB_FNameExt(). It extracts the extension from the filename.
I will create a table with the wanted extensions and set an index, only files with matching extension will be stored in the
movie.dbf.
Thx anyway.
Robert
Post Reply