FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Search directory for multiple files.
Posts: 598
Joined: Tue Apr 15, 2008 04:51 PM
Search directory for multiple files.
Posted: Sat Mar 13, 2010 01:53 AM

Within a directory I have several dbf files named "week13.d" with the last two digits of the extension in the name being any number
from 01 to 99. For example week13.d01, week13.d02 etc etc. there could be 99 files.

So what I need to do is search the directory for each file. Open the file search for the names of
other files which are listed in the "week13.d??" files. Then place the names of the files into a xbrowse.
Then continue the search process until I have all the names listed in the browse that are in the week13 files.

The customer will then browse the list and select the files to process.

Help. I don't know how to do thiis.

Thank you

Harvey
Posts: 1335
Joined: Fri Jun 13, 2008 11:04 AM
Re: Search directory for multiple files.
Posted: Sat Mar 13, 2010 06:13 AM
Dear Mr.Harvey,

Have you tried the Directory()

This example creates an array of information about files in the current directory and then lists the names of the files using AEVAL() and MsgInfo():
Code (fw): Select all Collapse
#include "Directory.ch"
aDirectory := DIRECTORY("week13.d??", "D")
AEVAL( aDirectory, {|aFile| MsgInfo(aFile[F_NAME])} )



Regards
Anser
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Search directory for multiple files.
Posted: Sat Mar 13, 2010 10:38 AM

It appears from Mr. Hag's posting that 'week13.d??' are not folders but only files. Each file containing names of other files.

Regards



G. N. Rao.

Hyderabad, India
Posts: 4043
Joined: Wed Dec 19, 2007 06:40 PM
Re: Search directory for multiple files.
Posted: Sat Mar 13, 2010 01:42 PM
1. I created the Dbf's => Week13.d01 - Week13.d05
2. In each Dbf, I added to the Field INFO -> Test1 - 3
3. Next I scan with Directory for all Week13.d* ( Array aDirectory includes all Filenames )
4. I open in a FOR NEXT each Dbf and add to the Array cList the File-name and the Dbf-Field Info



Code (fw): Select all Collapse
#include "FiveWin.ch"
#include "xBrowse.ch"
#include "Directory.ch"

FUNCTION  Main()
local oDlg, oBrw
local cList := {}

aDirectory := DIRECTORY("week13.d*")
n:= 1

FOR n := 1 TO LEN( aDirectory )
        cFile :=  aDirectory[n][1]
        DBSELECTAREA(1)
    USE "&cFile"
    DBGOTOP()
    DO WHILE !EOF()
        AADD( cList, { cFile, (1)->Info } )
        DBSKIP( + 1 )
    ENDDO
    CLOSE                   
NEXT

DEFINE DIALOG oDlg SIZE 300, 200

@ 0, 0 XBROWSE oBrw OF oDlg  ARRAY  cList   AUTOCOLS
      
oBrw:CreateFromCode() 
oBrw:bKeyDown = { || oDlg:SetText( Str( oBrw:nColSel ) ) }  
      
ACTIVATE DIALOG oDlg CENTER ON INIT ( oDlg:oClient := oBrw, oDlg:Resize() )

RETURN NIL


Best Regards
Uwe :-)
Since 1995 ( the first release of FW 1.9 )

i work with FW.

If you have any questions about special functions, maybe i can help.
Posts: 4043
Joined: Wed Dec 19, 2007 06:40 PM
Re: Search directory for multiple files.
Posted: Sat Mar 13, 2010 01:54 PM
// Within a directory I have several dbf files named "week13.d"
// with the last two digits of the extension in the name being any number
// from 01 to 99. For example week13.d01, week13.d02 etc etc. there could be 99 files.
// So what I need to do is search the directory for each file.
// Open the file search for the names of
// other files which are listed in the "week13.d??" files.
// Then place the names of the files into a xbrowse.
// Then continue the search process until I have all the names listed in the browse
// that are in the week13 files
.
// The customer will then browse the list and select the files to process.

Harvey, You can do it different to my Solution, if You like :
1. Scan for all Files.
2. Display the Files in xBrowse.
3. Select the File.
4. Display the Field in another Browse

With this Solution, I collect all Infos from all DBF's
The Strings : Test1, Test2, Test3 will be Your Filenames.

1. I created the Dbf's => Week13.d01 - Week13.d05
2. each Dbf includes the Field INFO with Strings -> "Test1" - "Test3"
3. Next I scan with Directory for all Week13.d* ( the Array aDirectory includes all Filenames )
4. I open in a FOR NEXT each Dbf and add to the Array cList the File-Name and the Dbf-Field Info



Code (fw): Select all Collapse
#include "FiveWin.ch"
#include "xBrowse.ch"
#include "Directory.ch"

FUNCTION  Main()
local oDlg, oBrw
local cList := {}

aDirectory := DIRECTORY("week13.d*")
n:= 1

FOR n := 1 TO LEN( aDirectory )
        cFile :=  aDirectory[n][1]
        DBSELECTAREA(1)
    USE "&cFile"
    DBGOTOP()
    DO WHILE !EOF()
        AADD( cList, { cFile, (1)->Info } )
        DBSKIP( + 1 )
    ENDDO
    CLOSE                   
NEXT

DEFINE DIALOG oDlg SIZE 300, 200

@ 0, 0 XBROWSE oBrw OF oDlg  ARRAY  cList   AUTOCOLS
      
oBrw:CreateFromCode() 
oBrw:bKeyDown = { || oDlg:SetText( Str( oBrw:nColSel ) ) }  
      
ACTIVATE DIALOG oDlg CENTER ON INIT ( oDlg:oClient := oBrw, oDlg:Resize() )

RETURN NIL


Best Regards
Uwe :-)
Since 1995 ( the first release of FW 1.9 )

i work with FW.

If you have any questions about special functions, maybe i can help.
Posts: 598
Joined: Tue Apr 15, 2008 04:51 PM
Re: Search directory for multiple files.
Posted: Sat Mar 13, 2010 04:11 PM

Uwe:
I just got the code you sent and I'll be trying it out. Thanks so much for you help. Always appreciated.

Harvey

Thank you

Harvey

Continue the discussion