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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Listing directories and files

Status
Not open for further replies.

Domino2

Technical User
Jun 8, 2008
475
GB
I am using this section of code to go through a known directory, and put subdirectory names into lists, as well as filenames within the directories.

Sub ListFilesAndSubFolders(fld As Object)

Dim fil As Object
Dim sfl As Object

For Each sfl In fld.SubFolders

Me.List3.AddItem UCase(sfl.Name) ' Puts directory name in list

ParseFolder2 "k:\Documents" & "\" & sfl.Name ' Puts all files found in
main direcotory in another list

ParseFolder3 "k:\Documents" & "\" & sfl.Name ' Puts Subdirectory names in another list

Next sfl

End Sub


Sub ParseFolder3(FolderName3 As String)
Dim fso As Object
Dim fld As Object
Set fso = CreateObject("Scripting.FileSystemObject")
Set fld = fso.GetFolder(FolderName3)
Call ListFilesAndSubFolders3(fld)
End Sub


Sub ListFilesAndSubFolders3(fld As Object)
Dim fil As Object
Dim sfl As Object
For Each sfl In fld.SubFolders
Me.List3b.AddItem sfl.Name
Next sfl
End Sub


This all works, however if there are two directories both containing the same files, it lists the first set directories in accending order but when it lists the second duplicate set of subdirectory names they are listed in descending order?

Any ideas, thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top