Search directory for multiple files.

Search directory for multiple files.

Postby hag » Sat Mar 13, 2010 1: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
hag
 
Posts: 598
Joined: Tue Apr 15, 2008 4:51 pm
Location: LOs Angeles, California

Re: Search directory for multiple files.

Postby anserkk » Sat Mar 13, 2010 6: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: Select all  Expand view
#include "Directory.ch"
aDirectory := DIRECTORY("week13.d??", "D")
AEVAL( aDirectory, {|aFile| MsgInfo(aFile[F_NAME])} )
 



Regards
Anser
User avatar
anserkk
 
Posts: 1332
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India

Re: Search directory for multiple files.

Postby nageswaragunupudi » 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
User avatar
nageswaragunupudi
 
Posts: 10627
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Search directory for multiple files.

Postby ukoenig » Sat Mar 13, 2010 1: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

Image

Code: Select all  Expand view

#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 :lol:
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.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: Search directory for multiple files.

Postby ukoenig » Sat Mar 13, 2010 1: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

Image

Code: Select all  Expand view

#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 :lol:
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.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: Search directory for multiple files.

Postby hag » Sat Mar 13, 2010 4: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
hag
 
Posts: 598
Joined: Tue Apr 15, 2008 4:51 pm
Location: LOs Angeles, California


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 90 guests