ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   FileSearch behaviour (https://www.excelbanter.com/excel-programming/354723-filesearch-behaviour.html)

kjs[_2_]

FileSearch behaviour
 
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



Tom Ogilvy

FileSearch behaviour
 
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

--
Regards,
Tom Ogilvy


"kjs" wrote in message
...
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





kjs[_2_]

FileSearch behaviour
 
"Tom Ogilvy" wrote in message ...
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

--
Regards,
Tom Ogilvy


"kjs" wrote in message
...
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 problems all stemmed from having 'view hidden files & folders' checked.
The system folders had references to the contents of the stick etc.

Kevin




All times are GMT +1. The time now is 03:35 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com