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!

Can I get a recursive list of files using filesystemobject?

Status
Not open for further replies.

mymou

Technical User
May 21, 2001
355
GB


Hi all

It is simple enough to pull a single level of subfolders (and their files) using filesystemobject but to get a full list of all files and folders is beyond my capabilities.

Have seen the winseek.vbp but would rather stick to what i know if possible.

Also, I have seen some people using early binding with filesystemobject - I dont seem to be able to - am i missing something?

Thanks in advance.


Stew

 
Hi,

Here's some code that populates a treeview with the directories. If you need more help, let me know.

------------------------------------------------------------
'Place a treeview and a command button on a form.
Dim LocalFileSystem
Dim ADrive As Variant

Private Sub Command1_Click()
Set LocalFileSystem = CreateObject("Scripting.FileSystemObject")
For Each ADrive In LocalFileSystem.Drives
If ADrive.IsReady Then
TreeView1.Nodes.Add , , ADrive.DriveLetter & ":\", ADrive
AddFolder (ADrive.DriveLetter & ":\")
End If
Next ADrive
End Sub

Function AddFolder(node As String)
Dim AFolder As Variant
Set TheFolders = LocalFileSystem.GetFolder(node)
For Each AFolder In TheFolders.SubFolders
TreeView1.Nodes.Add node, tvwChild, AFolder, AFolder
AddFolder (AFolder)
Next
DoEvents
End Function
------------------------------------------------------------

:) Sunaj
 


Thanks Sunaj


Never used a treeview before. Havent worked it though yet - but it looks like it has real potential - although it is much more (prettier) than I need it to be.

Also, its interesting the way that the function calls itself. Never thought of that before. I will go and play for a while and get back to you - it might be the solution I was originally looking for.

Thanks.


Stew
 


Here what i wanted to do - thanks for the inspiration!!


Sub GenerateAllFolderInformation(Folder)

Dim S
Dim SubFolders
Dim SubFolder
Dim Files
Dim File

Set Files = Folder.Files

If Files.Count <> 0 Then
For Each File In Files
Call StuffIWanToDo(File)
Next
End If

Set SubFolders = Folder.SubFolders

If SubFolders.Count <> 0 Then
For Each SubFolder In SubFolders
Call GenerateAllFolderInformation(SubFolder)
Next
End If

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top