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)
SET STEP ON
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)
ELSE
nLen = ALEN(aryParam)
IF !EMPTY(aryParam(nLen))
DIMENSION aryParam(nLen + 1)
nLen = nLen + 1
ENDIF
aryParam(nLen) = cDirectory + cFile
ENDIF
ENDIF
ENDFOR
ENDFUNC
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.