Log inUsernamePassword
Log me on automatically each visit    
Register
Register
Log in to check your private messages
Log in to check your private messages
Visual Basic Forum for Visual Basic Programmers VB Forum Index » Knowledge Base

Post new topic   Reply to topic
List all subfolders in a specific folder
View previous topic :: View next topic  
Author Message
P.T.A.M.
Administrator


Joined: 08 Oct 2003
Posts: 752
Location: Greece

PostPosted: Dec 29th, 2003 07:29 PM    Post subject: List all subfolders in a specific folder Reply with quote

Add a reference to the "Microsoft Scripting Runtime":

Code:
Private Sub Command1_Click()
    Dim strStartPath As String
    strStartPath = "C:\" 'ENTER YOUR START FOLDER HERE
    ListFolder strStartPath
End Sub

Private Sub ListFolder(sFolderPath As String)
    Dim FS As New FileSystemObject
    Dim FSfolder As Folder
    Dim subfolder As Folder
    Dim i As Integer
   
    Set FSfolder = FS.GetFolder(sFolderPath)

    For Each subfolder In FSfolder.SubFolders
        DoEvents
        i = i + 1
        Debug.Print subfolder
    Next subfolder
    Set FSfolder = Nothing
    MsgBox "Total sub folders in " & sFolderPath & " : " & i
End Sub

_________________
No one is completely useless. They can at least be an example of what to avoid.
Back to top
View user's profile Send private message Send e-mail Visit poster's website ICQ Number
P.T.A.M.
Administrator


Joined: 08 Oct 2003
Posts: 752
Location: Greece

PostPosted: Dec 29th, 2003 07:30 PM    Post subject: Reply with quote

Another way (Dir function) :

Code:
 Dim Mypath as string, MyName as String,iCount as integer
iCount=0
MyPath = "c:\"   ' Set the path.
MyName = Dir(MyPath, vbDirectory)   ' Retrieve the first entry.
Do While MyName <> ""   ' Start the loop.
   ' Ignore the current directory and the encompassing directory.
   If MyName <> "." And MyName <> ".." Then
      ' Use bitwise comparison to make sure MyName is a directory.
      If (GetAttr(MyPath & MyName) And vbDirectory) = vbDirectory Then
         Debug.Print MyName   ' Display entry only if it
         iCount=iCount+1
      End If   ' it represents a directory.
   End If
   MyName = Dir   ' Get next entry.
Loop


debug.print "No.of Folders in the selected path : " & iCount

_________________
No one is completely useless. They can at least be an example of what to avoid.
Back to top
View user's profile Send private message Send e-mail Visit poster's website ICQ Number
Display posts from previous:   
Post new topic   Reply to topic    Visual Basic Forum for Visual Basic Programmers VB Forum Index » Knowledge Base All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Visual Basic Forum runs phpBB | Forum Template © iOptional
VB Resources | SSL | Visual Basic