Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Recursive dir search

Status
Not open for further replies.

fortage

MIS
Jun 15, 2000
329
US
I'm trying to find all folders that start with "l2d" 1,2,3 or 4 directories below the starting point. How can this be done in vbscript??

Thanks
 
Use the file systems object to loop through the folders and sub folders. There may be a more efficent way to do this, any input would be appreciated :)


<%


Public Function GetFolderList(strPathName)
'Returns comma delimited string of folder names
' starting with &quot;l2d&quot; starting at the strPathName
' and going four levels deep


Dim objFSO, objFolders, objFolderL1, objFolderL2
Dim objFolderL3, objFolderL4
Dim tmp_r

Set objFSO = Server.CreateObject(&quot;Scripting.FileSystemObject&quot;)

If objFSO.FolderExists(strPathName) Then

Set objFolders = objFSO.GetFolder(strPathName).SubFolders

For Each objFolderL1 In objFolders
If Left(objFolderL1.Name,3) = &quot;l2d&quot; Then
'Do what ever you need done to the Level one folders
tmp_r = tmp_r & objFolderL1.Name & &quot;, &quot;

'Goto Level 2
For Each objFolderL2 In objFolderL1.SubFolders
If Left(objFolderL2.Name,3) = &quot;l2d&quot; Then
'Do stuff to the Level 2 Folders
tmp_r = tmp_r & objFolderL2.Name & &quot;, &quot;

'Goto Level 3
For Each objFolderL3 In objFolderL2.SubFolders
If Left(objFolderL3.Name,3) = &quot;l2d&quot; Then
'Do what ever you need to the Level 3 Folders
tmp_r = tmp_r & objFolderL3.Name & &quot;, &quot;

'Goto Level 4
For Each objFolderL4 In objFolder3.SubFolders
If Left(objFolderL4.Name,3) = &quot;l2d&quot; Then
'Do stuff to the Level 4 Folders
tmp_r = tmp_r & objFolderL4.Name & &quot;, &quot;

End If
Next
End If
Next
End If
Next
End If
Next

Else
tmp_r = &quot;Folder Does Not Exist&quot;
End If

GetFolderList = tmp_r

End Function



%>
 
This could be easyly resolved by a recursive call...
More details call me ;-) ________
George, M
email : shaddow11_ro@yahoo.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top