Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Get a collection of sub folders from a parent folder
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Divers
Thread ID:
00288982
Message ID:
00289080
Vues:
42
>>>>You should be able to get what you want from the ADIR() function.
>>>>
>>>>mnumdirs = adir(myarray, "c:\parent", "D")
>>>>
>>>>Is that what you were looking for?
>>>
>
>And how do reasonable people do this with Scripting.FileSystemObject? While I haven't 'classified' it yet, this is working FSO-based code, recursive, and doesn't change directories, of course:
>
>
>*Procedure file FSOTree
>FUNCTION GetTreeUsingFSO
>LPARAMETER taReturnArray, tcBaseFolder
>EXTERNAL ARRAY taReturnArray
>IF VARTYPE(tcBaseFolder) # 'C' OR ! DIRECTORY(FULLPATH(tcBaseFolder))
>   tcBaseFolder = FULLPATH(CURDIR())
>ENDIF
>LOCAL oFSO, oTopFolder
>oFSO = CREATEOBJ('Scripting.FileSystemObject')
>oTopFolder = oFSO.GetFolder(tcBaseFolder)
>DIMENSION taReturnArray[1]
>taReturnArray = NULL
>RecurseSubFoldersUsingFSO(oTopFolder,@taReturnArray)
>RETURN ALEN(taReturnArray)
>
>FUNCTION RecurseSubFoldersUsingFSO
>LPARAMETERS toFolderObj, taReturnArray
>EXTERNAL ARRAY taReturnArray
>LOCAL nSizeOfArray,oSubFolders
>nSizeOfArray = ALEN(taReturnArray) + IIF(ISNULL(taReturnArray[1]),0,1)
>DIMENSION taReturnArray[nSizeOfArray]
>taReturnArray[nSizeOfArray] = toFolderObj.path
>oSubFolders = toFolderObj.SubFolders
>FOR Each oFolder IN oSubFolders
>   RecurseSubFoldersUsingFSO(oFolder,@taReturnArray)
>ENDFOR
>RETURN
>
>SET PROC TO FSOTree ADDITIVE
>DECLARE aSubDirs[1]
>? GetTreeUsingFSO(aSubDirs,'C:\')
>disp memo like aSubDirs
>
>* The first function of the pair just does the setup of the FSO and array;  do it yourself,
>* and you can get several paths' trees into the same array
>
>SET PROC TO FSOTree ADDITIVE
>LOCAL oFSO, oTopFolder, aSubDirs[1]
>aSubDirs[1] = NULL
>oFSO = CREATEOBJ('Scripting.FileSystemObject')
>oTopFolder = oFSO.GetFolder('C:\Windows')
>RecurseSubFolders(oTopFlder,@aSubDirs)
>oTopFolder = oFSO.GetFolder('C:\Program Files')
>RecurseSubFolders(oTopFolder,@aSubDirs)
>disp memo like aSubDirs
Show off!:-) Seriously, do you want me to test this against my routing using ADIR()? Just for grins, of course.
George

Ubi caritas et amor, deus ibi est
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform