get every folder on the drive! recurse sub folders directories
nice n easy..
first click project -> references, and check Microsoft Scripting Runtime
Win 98 SE and before will need a newer version of scrrun.dll
VB Code:
Public Function GetFolders(sStartFolder As String) As String
On Error Resume Next
Dim fso As New FileSystemObject
Dim f As Folder
Dim fldr As Folder
Set fldr = fso.GetFolder(sStartFolder)
GetFolders = fldr.Path & vbCrLf
If fldr.SubFolders.Count > 0 Then
For Each f In fldr.SubFolders
GetFolders = GetFolders & GetFolders(f.Path)
Next
End If
If Err.Number = 92 Then GetFolders = vbNullString
'windows did not allow the program to look inside this folder, so ignore it completely (ie c:\system volume information in win2000)
End Function
note - the code got an edit recently... the following posts may or may not make sense ;)
Re: get every folder on the drive! recurse sub folders directories
Quote:
Originally posted by dis1411
note - the returned string will contain an extra vbCrLf at the beginning.. its not that bad cuz most likely youll split the string into an array and you can start at 1 instead of 0 when processing it
Just change your code one tiny bit to fix that, why don't you...
VB Code:
Private Function Getfolders(sStartFolder As String) As String
Dim fso As New FileSystemObject
Dim f As Folder
Dim fldr As Folder
Set fldr = fso.GetFolder(sStartFolder)
Getfolders = fldr.Path & VbCrLf
If fldr.SubFolders.Count > 0 And Getfolders <> "" Then
For Each f In fldr.SubFolders
Getfolders = Getfolders & Getfolders(f.Path)
Next f
End If
End Function
Re: get every folder on the drive! recurse sub folders directories
very goooooooooood
thanks