craigsboyd
IS-IT--Management
I wrote this code in response to a question in thread184-671687 It 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. 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)
*!* EXTERNAL ARRAY aryAllFiles
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
Slighthaze = NULL
[ul][li]FAQ184-2483
An excellent guide to getting a fast and accurate response to your questions in this forum.[/li][/ul]
Dimension aryFiles(1)
=GetAllFiles(GETDIR(), @aryFiles)
SET STEP ON
FUNCTION GetAllFiles(cDirectory, aryParam)
*!* EXTERNAL ARRAY aryAllFiles
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 == "."


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
Slighthaze = NULL
[ul][li]FAQ184-2483
An excellent guide to getting a fast and accurate response to your questions in this forum.[/li][/ul]