list filenames without path

Bram de Groot

New member
Local time
Today, 06:47
Joined
Feb 18, 2004
Messages
7
I managed to list filenames using the following code:


With Application.FileSearch
.NewSearch
.LookIn = MyValue
.SearchSubFolders = True
.filename = ""
.FileType = msoFileTypeAllFiles
If .Execute() > 0 Then
For i = 1 To .FoundFiles.Count
rstmdb.AddNew
rstmdb("FileName") = .FoundFiles(i)
rstmdb.Update
Next i
Else
MsgBox "There were no files found."
End If
End With
rstmdb.Close


This gives me a list of filenames with their path. Is there a way to list only the filenames?

Thanks!
Bram de Groot
 
Hope this helps but I just loop through the foundfiles and capture the names by string delimination. You can just use the filename to get that information.

Code:
Dim filename As String, filepath As String
Dim Trigger As Integer


Trigger = InStrRev(.FoundFiles(I), "\")
filename = Mid(.FoundFiles(I), Trigger + 1) 'find filename
filepath = Mid(.FoundFiles(I), 1, Trigger) 'find files path

the I in .foundfiles(I) represents an I from a for loop such as

for I = 1 to .founfiles.count

next I
 
That's what I was looking for! Thanks!
 

Users who are viewing this thread

Back
Top Bottom