|
-
Mar 6th, 2006, 05:09 PM
#1
Thread Starter
Frenzied Member
Get file locations within directory
Hi fellas
Right consider i have a folder, like my pictures, for every file within that folder and subfolders, i need the path.
eg
c:\documents and settings\ben\my documents\my pictures\logo.gif
c:\documents and settings\ben\my documents\my pictures\vbf\program.jpg
c:\documents and settings\ben\my documents\my pictures\site.png
Any ideas?
Thanks all, ILMV
-
Mar 6th, 2006, 05:28 PM
#2
Hyperactive Member
Re: Get file locations within directory
I did something similar to this while searching for a file and found some helpful code so here ya go hope it helps
VB Code:
Public Function RecurseFolderList(FolderName As String) As Boolean
On Error GoTo errHandler
Dim fso, f, fc, fj, f1
Set fso = CreateObject("Scripting.FileSystemObject")
If Err.Number > 0 Then
RecurseFolderList = False
Exit Function
End If
On Error GoTo errHandler
If fso.FolderExists(FolderName) Then
Set f = fso.GetFolder(FolderName)
Set fc = f.Subfolders
Set fj = f.Files
For Each f1 In fc
RecurseFolderList (f1)
Next
For Each f1 In fj
List1.AddItem f1
DoEvents: DoEvents
Next
Set f = Nothing
Set fc = Nothing
Set fj = Nothing
Set f1 = Nothing
Else
RecurseFolderList = False
End If
Set fso = Nothing
Exit Function
errHandler:
Resume Next
End If
End Function
Private Sub Form_Load()
Me.Show
RecurseFolderList "C:\documents and settings"
MsgBox "Done"
End
End Sub
be sure to change the dir to what u want as this setting will give many results
-
Mar 7th, 2006, 06:51 AM
#3
Re: Get file locations within directory
I buried this gif file nine folders deep and it found it very quickly.
VB Code:
Option Explicit
Private Declare Function SearchTreeForFile Lib "imagehlp" _
(ByVal RootPath As String, ByVal InputPathName As String, _
ByVal OutputPathBuffer As String) As Long
Private Const MAX_PATH = 260
Private Sub Command1_Click()
Dim tempStr As String, Ret As Long
'create a buffer string
tempStr = String(MAX_PATH, 0)
'returns 1 when successfull, 0 when failed
Ret = SearchTreeForFile("c:\", "ivy.gif", tempStr)
If Ret <> 0 Then
MsgBox "Located file at " + Left$(tempStr, InStr(1, tempStr, Chr$(0)) - 1)
Else
MsgBox "File not found!"
End If
End Sub
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
|