Information générale
Catégorie:
Codage, syntaxe et commandes
Titre:
My Directory Recursive Sample Code
Versions des environnements
I heavily modified some code I found from a Michael Reynolds. It works like Adir() but has full file paths for every file and every subdirectory and subdirectory file below the passed path.
*!*this fills the passed array (1,5) with full file paths for all files and directories *!*below the
*!*passed path as well as file attributes, array must be passed by name, the last row *!*in the
*!*array is blank
Function Recurse
LPARAMETERS pcDir, lcPaths
Local lnPtr, lnFileCount, laFileList, lcDir, lcFile
IF RIGHT(pcDir,1) != "\"
pcDir = pcDir + "\"
ENDIF
IF DIRECTORY(pcDir) = .F.
RETURN 1
ENDIF
Dimension laFileList(1)
*Read the chosen directory.
lnFileCount = Adir(laFileList, pcDir + '*.*', 'D')
For lnPtr = 1 To lnFileCount
If 'D' $ laFileList(lnPtr, 5)
*Get directory name.
lcDir = laFileList(lnPtr, 1)
*Ignore current and parent directory pointers.
If lcDir != '.' And lcDir != '..'
&lcPaths(Alen(&lcPaths,1), 1) = pcDir + lcDir
*Expand the array one row
Dimension &lcPaths(Alen(&lcPaths,1) + 1, 5)
*Call this routine again.
Recurse(pcDir + lcDir, lcPaths)
Endif
Else
*Get the file properties.
&lcPaths(Alen(&lcPaths,1), 1) = pcDir + laFileList(lnPtr,1)
&lcPaths(Alen(&lcPaths,1), 2) = pcDir + ALLTRIM(STR(laFileList(lnPtr,2)))
&lcPaths(Alen(&lcPaths,1), 3) = pcDir + DTOC(laFileList(lnPtr,3))
&lcPaths(Alen(&lcPaths,1), 4) = pcDir + laFileList(lnPtr,4)
&lcPaths(Alen(&lcPaths,1), 5) = pcDir + laFileList(lnPtr,5)
*Expand the array one row
Dimension &lcPaths(Alen(&lcPaths,1) + 1, 5)
Endif
ENDFOR
RETURN 0
Endfunc
Suivant
Répondre
Voir le fil de ce thread
Voir le fil de ce thread à partir de ce message seulement
Voir tous les messages de ce thread
Voir tous les messages de ce thread à partir de ce message seulement