FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Array of files indirectory and subdirectory's
Posts: 1195
Joined: Mon Oct 17, 2005 05:41 AM
Array of files indirectory and subdirectory's
Posted: Wed Nov 07, 2018 03:47 PM
Hi,

I want a list of all files in a directory and the files in all subdirectory.
Is there an easy way to do this, or do I have to het all files an directory of the main one, and then again of all subdirectory's

I was already thinking to do a dir /s to a file, and read that, and add it to an array.
Regards,

Marc



FWH32+xHarbour | FWH64+Harbour | BCC | DBF | ADO+MySQL | ADO+MariaDB | ADO+SQLite
Posts: 8515
Joined: Tue Dec 20, 2005 07:36 PM
Re: Array of files indirectory and subdirectory's
Posted: Wed Nov 07, 2018 04:23 PM
Code (fw): Select all Collapse
#include "FiveWin.Ch"
#include "Directry.ch"

#define CLR_LGREEN    nRGB( 190, 215, 190 )
#define CLR_LGRAY     nRGB( 230, 230, 230 )
#define CLR_VERMELHO  nRGB( 255, 000, 000 )
#define CLR_AMARELO   nRGB( 255, 255, 000 )

STATIC nBytes, nDisks
STATIC lnKeyEscape := .F.

FUNCTION Backup()  // Procedimentos do Backup

   LOCAL oSetupDlg, nDriveTo := 1, cDriveTo, nDriveCap := 4
   LOCAL lGoOn, aFiles[1],  aFileList, x, iDcor, oFont, oBackup
   LOCAL oDlg, oBrw, n := 1
   LOCAL oAceitar, oCancelar, nKey := VK_RETURN

   LOCAL aDbfs := Directory( "*.DBF" )

   IF Len( aDbfs ) < 1
      RETURN Nil
   ENDIF

   aSort( aDbfs, , , { |x, y | x[1] < y[1] } )

   DEFINE FONT oFont NAME "Arial"         SIZE 0, 16 BOLD

   DEFINE DIALOG oDlg FROM 6, 20 TO 25, 78        ;
      TITLE "Browse dos Arquivos DBFs em: " + ;
      CurDir() + " Para Copiar"               ;
      STYLE nOR( WS_BORDER, WS_THICKFRAME )   ;
      COLORS CLR_BLACK, nRGB( 193, 205, 205 )

   @ 1, 2 ListBox oBrw Fields aDbfs[n][1], ;
      Str( aDbfs[n][2], 10, 0 ),           ;
      Dtoc( aDbfs[n][3] ),                 ;
      aDbfs[n][4]                          ;
      Headers "Nome do Arquivo",           ;
      "Tamanho", "Data", "Hora"            ;
      FieldSizes 120, 80, 80, 60           ;
      COLOR CLR_HBLUE, CLR_AMARELO         ;
      FONT oFont                           ;
      Of oDlg Size 200, 100

   oBrw:bGotop    := { || N := 1 }
   oBrw:bGoBottom := { || N := Eval( oBrw:bLogicLen ) }
   oBrw:bSkip     := { | nWant, nOld | nOld := N , N += nWant, ;
      N := Max( 1, Min( N, Eval( oBrw:bLogicLen ) ) ), ;
      N - nOld }
   oBrw:bLogicLen := { || Len( aDbfs ) }
   oBrw:cAlias    := "Array"
   oBrw:nClrBackHead  := CLR_LGREEN
   oBrw:nClrBackFocus := CLR_HRED
   oBrw:nClrForeFocus := CLR_AMARELO
   oBrw:nClrForeHead  := CLR_HRED
   oBrw:nColAct       := 1
   oBrw:nLineStyle    := 3
   oBrw:lCellStyle    := .T.
   oBrw:aJustify      := { .F. , .F. , .F. , .F. }
   oBrw:lMChange      := .F.
   oBrw:SetFocus()
   oBrw:Refresh()


   @ 6.6, 16 Button oBackup           ;
      PROMPT "&Test" Of oDlg   ;
      Action( oDlg:End() )     ;
      SIZE 40, 12              ;
      CANCEL

   ACTIVATE DIALOG oDlg CENTERED

   oFont:End()

RETURN NIL


Regards, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
Posts: 1195
Joined: Mon Oct 17, 2005 05:41 AM
Re: Array of files indirectory and subdirectory's
Posted: Wed Nov 07, 2018 04:34 PM

Thank you for the responce, but I think you misunderstood the question.
I want an array of all files in thaa directory AND also all files in the subdirectories

Regards,

Marc



FWH32+xHarbour | FWH64+Harbour | BCC | DBF | ADO+MySQL | ADO+MariaDB | ADO+SQLite
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: Array of files indirectory and subdirectory's
Posted: Wed Nov 07, 2018 05:43 PM

Try DIRECTORYRECURSE() function.

EMG

Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: Array of files indirectory and subdirectory's
Posted: Wed Nov 07, 2018 05:43 PM
With Harbour
Code (fw): Select all Collapse
HB_dirScan( cPath, cMask, "A" )
Cristobal Navarro

Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo

El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
Posts: 1195
Joined: Mon Oct 17, 2005 05:41 AM
Re: Array of files indirectory and subdirectory's
Posted: Wed Nov 07, 2018 05:57 PM
Thank you,

Now I remember that I asked this a long time before, and I allways get an empty array.
http://forums.fivetechsupport.com/viewtopic.php?f=3&t=22789&p=121743&hilit=DIRECTORYRECURSE#p121743
When I use mu old version of FW with xharbour, I still get an empty array, but with my newer version with harbour, it worked :-)
Regards,

Marc



FWH32+xHarbour | FWH64+Harbour | BCC | DBF | ADO+MySQL | ADO+MariaDB | ADO+SQLite
Posts: 8515
Joined: Tue Dec 20, 2005 07:36 PM
Re: Array of files indirectory and subdirectory's
Posted: Wed Nov 07, 2018 06:57 PM
Code (fw): Select all Collapse
#include "FiveWin.Ch"
#include "Directry.ch"

#define CLR_LGREEN    nRGB( 190, 215, 190 )
#define CLR_LGRAY     nRGB( 230, 230, 230 )
#define CLR_VERMELHO  nRGB( 255, 000, 000 )
#define CLR_AMARELO   nRGB( 255, 255, 000 )

STATIC nBytes, nDisks
STATIC lnKeyEscape := .F.

FUNCTION Backup()  // Procedimentos do Backup

   LOCAL oSetupDlg, nDriveTo := 1, cDriveTo, nDriveCap := 4
   LOCAL lGoOn, aFiles[1],  aFileList, x, iDcor, oFont, oBackup
   LOCAL oDlg, oBrw, n := 1
   LOCAL oAceitar, oCancelar, nKey := VK_RETURN

   //LOCAL aDbfs := Directory( "*.DBF" )
   LOCAL aDbfs := DirectoryRecurse( "C:\FWH1701\*.*" )

   IF Len( aDbfs ) < 1
      RETURN Nil
   ENDIF

   aSort( aDbfs, , , { |x, y | x[1] < y[1] } )

   DEFINE FONT oFont NAME "Arial"         SIZE 0, 16 BOLD

                        // 6, 20 TO 25, 78
   DEFINE DIALOG oDlg FROM 6, 20 TO 25, 90        ;
      TITLE "Browse dos Arquivos DBFs em: " + ;
      CurDir() + " Para Copiar"               ;
      STYLE nOR( WS_BORDER, WS_THICKFRAME )   ;
      COLORS CLR_BLACK, nRGB( 193, 205, 205 )

   @ 1, 2 ListBox oBrw Fields aDbfs[n][1], ;
      Str( aDbfs[n][2], 10, 0 ),           ;
      Dtoc( aDbfs[n][3] ),                 ;
      aDbfs[n][4]                          ;
      Headers "Nome do Arquivo",           ;
      "Tamanho", "Data", "Hora"            ;
      FieldSizes 270, 80, 80, 60           ;
      COLOR CLR_HBLUE, CLR_AMARELO         ;
      FONT oFont                           ;
      Of oDlg Size 260, 100

   oBrw:bGotop    := { || N := 1 }
   oBrw:bGoBottom := { || N := Eval( oBrw:bLogicLen ) }
   oBrw:bSkip     := { | nWant, nOld | nOld := N , N += nWant, ;
      N := Max( 1, Min( N, Eval( oBrw:bLogicLen ) ) ), ;
      N - nOld }
   oBrw:bLogicLen := { || Len( aDbfs ) }
   oBrw:cAlias    := "Array"
   oBrw:nClrBackHead  := CLR_LGREEN
   oBrw:nClrBackFocus := CLR_HRED
   oBrw:nClrForeFocus := CLR_AMARELO
   oBrw:nClrForeHead  := CLR_HRED
   oBrw:nColAct       := 1
   oBrw:nLineStyle    := 3
   oBrw:lCellStyle    := .T.
   oBrw:aJustify      := { .F. , .F. , .F. , .F. }
   oBrw:lMChange      := .F.
   oBrw:SetFocus()
   oBrw:Refresh()


   @ 6.6, 16 Button oBackup           ;
      PROMPT "&Test" Of oDlg   ;
      Action( oDlg:End() )     ;
      SIZE 40, 12              ;
      CANCEL

   ACTIVATE DIALOG oDlg CENTERED

   oFont:End()

RETURN NIL


Regards, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341

Continue the discussion