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:
00289084
Vues:
32
>>>>>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.

Sure - I've never benchmarked it against a recursive ADIR(); I like it because the code is nice and clean. I suspect ADIR() and the ACOPY() approach might be faster, but one obvious advantage is that this doesn't run into the bad behavior of ADIR() with regard to funky directory names like:

"C:\My.nasty.dir name\another problem. . .for adir"
EMail: EdR@edrauh.com
"See, the sun is going down..."
"No, the horizon is moving up!"
- Firesign Theater


NT and Win2K FAQ .. cWashington WSH/ADSI/WMI site
MS WSH site ........... WSH FAQ Site
Wrox Press .............. Win32 Scripting Journal
eSolutions Services, LLC

The Surgeon General has determined that prolonged exposure to the Windows Script Host may be addictive to laboratory mice and codemonkeys
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform