|
-
Oct 21st, 2005, 08:23 PM
#1
Thread Starter
Fanatic Member
Files [Resolved]
Given a folder path, what would be the easiest way to loop through and find all filenames and folder names in the given path? Thanks.
Last edited by Nove; Oct 23rd, 2005 at 11:04 AM.
-
Oct 21st, 2005, 08:30 PM
#2
Fanatic Member
Re: Files
Does it have to be in the code? Because you can use a FileListBox and in Form_Load event put File1.Path = "Location of folder"
-
Oct 21st, 2005, 08:34 PM
#3
Thread Starter
Fanatic Member
Re: Files
I have to be able to retreive the filepaths of the folders and files so I can work with them programatically.
-
Oct 21st, 2005, 08:39 PM
#4
Re: Files
This loads the jpg images from a folder into a listbox, but you can change it to suit your wishes.
VB Code:
Option Explicit
Private Sub Form_Load()
Dim FileFinder$
FileFinder = Dir("d:\temp\*.jpg")
Do Until FileFinder = ""
List1.AddItem LCase(FileFinder)
FileFinder = Dir
Loop
End Sub
-
Oct 22nd, 2005, 10:16 PM
#5
Thread Starter
Fanatic Member
Re: Files
Ok, that'll work great. Now, how would I find all the folders in the specified path?
-
Oct 23rd, 2005, 12:49 AM
#6
Re: Files
Try this code, it will walk the directory structure and give you all the folders and files within that directory. This example will fill a treeview with the same tree structure as the directory.
VB Code:
Private Sub ShowFolder(ByVal sFolder As String)
Dim sDir As String
Dim coll As Collection
Dim i As Long
Set coll = New Collection
sDir = Dir(sFolder & "\", vbDirectory + vbHidden + vbReadOnly)
With TreeView1
Do While sDir <> ""
If (GetAttr(sFolder & "\" & sDir) And vbDirectory) = vbDirectory Then
If sDir <> "." And sDir <> ".." Then
.Nodes.Add sFolder, tvwChild, sFolder & "\" & sDir, sDir
coll.Add sFolder & "\" & sDir
End If
Else 'It may be a file
.Nodes.Add sFolder, tvwChild, sFolder & "\" & sDir, sDir
End If
sDir = Dir
Loop
.Nodes(sFolder).Sorted = True
End With
For i = 1 To coll.Count
ShowFolder coll(i)
Next
Set coll = Nothing
End Sub
Private Sub Command1_Click()
With TreeView1
.Nodes.Clear
.Nodes.Add , , Text1.Text, Dir(Text1.Text, vbDirectory)
ShowFolder Text1.Text
End With
End Sub
hope this helps
-
Oct 23rd, 2005, 07:24 AM
#7
-
Oct 23rd, 2005, 11:03 AM
#8
Thread Starter
Fanatic Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|