Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
My Directory Recursive Sample Code
Message
De
10/06/2005 18:12:34
 
 
À
Tous
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Titre:
My Directory Recursive Sample Code
Versions des environnements
Visual FoxPro:
VFP 9
OS:
Windows 2000 SP4
Divers
Thread ID:
01022342
Message ID:
01022342
Vues:
62
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
Fil
Voir

Click here to load this message in the networking platform