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

How do you parse the folder tree?

Status
Not open for further replies.

colezpapa3

Programmer
Dec 8, 2007
73
US
I want to load all the subdirectories and files from each subdirectory into a table - so I can load 'em into a list box for a user to select.
Problem is my ParseFolders routine is loading all the subdirectories as separate folders...I dont see them in their proper sequence....Attached is the code.
I am looking to see

Folder
--- subDirectory
files
files
files
--- subDirectory
files
files
Folder
--- subDirectory
...


Sub ParseFolders(objFSO, strPath)

Dim ThisFolder, ThisFolderSubs
Dim intItem As Integer
Dim ctlList As Access.ListBox
Dim x, y, z
Dim objFile As File

Dim db As Database
Dim rs As Recordset

Set db = CurrentDb
Set rs = db.OpenRecordset("AllFiles")


Debug.Print strPath

Set ThisFolder = objFSO.GetFolder(strPath)
Set ThisFolderSubs = ThisFolder.SubFolders


For Each objFolder In ThisFolderSubs

x = StrReverse(objFolder)
y = InStr(x, "\")
z = Mid$(x, 1, y)
z = StrReverse(z)


With rs

For Each objFile In objFolder.Files
' Me.ctlList.AddItem objFile.Name
rs.AddNew
rs!SubFolder = z
rs!Filename = objFile.Name
rs.Update
Next


End With

ParseFolders objFSO, objFolder.Path
Next objFolder

Me.ctlList.Requery

Set rs = Nothing
Set db = Nothing

End Sub
 
Do you have an autonumber on the file for sort order?
 
Access does not have any order to tables unless you create one. Try an autonumber and see if it suits.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top