FileSearch behaviour

K

kjs

FileSearch is producing duplicate results - listing the same file twice in
the FileSearch object. Additionally it's listing files outside the specified
"C:\" drive. Some are found in the E drive, which is a flash stick. Even
when this stick has been pulled out. Even when it's been pulled out
and the computer restarted! I guess the search results are stored
somewhere, but am clueless about the duplicates.

Kevin.

The code used:

Public Sub SearchForXLsheets()

Dim oFound As FileSearch
Dim l As Long

Set oFound = Application.FileSearch
With oFound
.NewSearch
.LookIn = "C:\"
.SearchSubFolders = True
.FileType = msoFileTypeExcelWorkbooks
.Execute SortBy:=msoSortByFileName
If .FoundFiles.Count > 0 Then
For l = 1 To .FoundFiles.Count
Cells(l, 1).Value = .FoundFiles(l)
Next l
End If
Columns("A:A").EntireColumn.AutoFit
End With
Set oFound = Nothing

End Sub
 
K

kjs

Tom Ogilvy said:
I have heard people say FileSearch is problematic, but never anything like
you describe. Here are some alternate approaches:

http://support.microsoft.com/kb/185476/EN-US/
How To Search Directories to Find or List Files

http://support.microsoft.com/kb/185601/EN-US/
HOW TO: Recursively Search Directories by Using FileSystemObject

The problems all stemmed from having 'view hidden files & folders' checked.
The system folders had references to the contents of the stick etc.

Kevin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top