Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Microsoft: FoxPro FAQ

Usefull Functions & Procedures

Get Files in Directory (including subdirectories) by craigsboyd
Posted: 4 Oct 03 (Edited 18 Feb 05)

Slighthaze = NULL

The following code will fill up the array aryFiles with a list of all the files (fullpath) in the selected directory (including subdirectories).  Besides being useful it is a good example of using recursion.  No external DLLs or COM objects are required, this solution is pure VFP.  The SET STEP ON line is so that you can easily see the resultant array in the debugger's LOCALS window.  Cut-n-paste the code below into a prg file and run it from within VFP to see how it works.

Dimension aryFiles(1)
=GetAllFiles(GETDIR(), @aryFiles)

FUNCTION GetAllFiles(cDirectory, aryParam)
    LOCAL ARRAY aryTemp(1,5)
    LOCAL nCount, nMax, nLen, cFile
    SET DEFAULT TO (cDirectory)
    =ADIR(aryTemp, "*.*","AHRSD",1)
    nMax = ALEN(aryTemp,1)
    FOR nCount = 1 TO nMax
        cFile = ALLTRIM(aryTemp(nCount,1))
        IF !(cFile == ".") AND !(cFile == "..")
            IF "D" $ aryTemp(nCount,5)
                =GetAllFiles(ADDBS(cDirectory + cFile), @aryParam)
                nLen = ALEN(aryParam)
                IF !EMPTY(aryParam(nLen))
                    DIMENSION aryParam(nLen + 1)
                    nLen = nLen + 1
                aryParam(nLen) = cDirectory + cFile

Back to Microsoft: FoxPro FAQ Index
Back to Microsoft: FoxPro Forum

My Archive

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close