| View previous topic :: View next topic |
| Author |
Message |
P.T.A.M. Administrator

Joined: 08 Oct 2003 Posts: 752 Location: Greece
|
Posted: Dec 29th, 2003 07:29 PM Post subject: List all subfolders in a specific folder |
|
|
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 |
|
P.T.A.M. Administrator

Joined: 08 Oct 2003 Posts: 752 Location: Greece
|
Posted: Dec 29th, 2003 07:30 PM Post subject: |
|
|
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 |
|
|