Array of files indirectory and subdirectory's

Array of files indirectory and subdirectory's

Postby Marc Vanzegbroeck » Wed Nov 07, 2018 3: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
Marc Vanzegbroeck
 
Posts: 1159
Joined: Mon Oct 17, 2005 5:41 am
Location: Belgium

Re: Array of files indirectory and subdirectory's

Postby karinha » Wed Nov 07, 2018 4:23 pm

Code: Select all  Expand view

#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
User avatar
karinha
 
Posts: 7794
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: Array of files indirectory and subdirectory's

Postby Marc Vanzegbroeck » Wed Nov 07, 2018 4: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
Marc Vanzegbroeck
 
Posts: 1159
Joined: Mon Oct 17, 2005 5:41 am
Location: Belgium


Re: Array of files indirectory and subdirectory's

Postby cnavarro » Wed Nov 07, 2018 5:43 pm

With Harbour
Code: Select all  Expand view

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
User avatar
cnavarro
 
Posts: 6541
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: Array of files indirectory and subdirectory's

Postby Marc Vanzegbroeck » Wed Nov 07, 2018 5: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
Marc Vanzegbroeck
 
Posts: 1159
Joined: Mon Oct 17, 2005 5:41 am
Location: Belgium

Re: Array of files indirectory and subdirectory's

Postby karinha » Wed Nov 07, 2018 6:57 pm

Code: Select all  Expand view

#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
User avatar
karinha
 
Posts: 7794
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 59 guests