Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default FileSearch gives unexpected result

The following code gives a found files count of 3 where only 1 file
exists.
set fs = Application.FileSearch
With fs
.NewSearch
.FileName = "EXCEL.exe"
.LookIn = "C:\Program Files"
.SearchSubFolders = True
.MatchTextExactly = True
.FileType = msoFileTypeAllFiles
End With
fs.Execute

For r = 1 To fs.FoundFiles.Count
MsgBox fs.FoundFiles(r)
Next r


The MsgBox refers to the same file each time "C:\Program
Files\Micrsoft Office\Office\EXCEL.exe"

Any thoughts on how to refine the code to give the expected answer?

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default FileSearch gives unexpected result

Mine finds just one.
So I created a shortcut to Excel.exe. Now it finds two! This could be your
problem.


"Stephen Allen" wrote in message
...
The following code gives a found files count of 3 where only 1 file
exists.
set fs = Application.FileSearch
With fs
.NewSearch
.FileName = "EXCEL.exe"
.LookIn = "C:\Program Files"
.SearchSubFolders = True
.MatchTextExactly = True
.FileType = msoFileTypeAllFiles
End With
fs.Execute

For r = 1 To fs.FoundFiles.Count
MsgBox fs.FoundFiles(r)
Next r


The MsgBox refers to the same file each time "C:\Program
Files\Micrsoft Office\Office\EXCEL.exe"

Any thoughts on how to refine the code to give the expected answer?



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default FileSearch gives unexpected result

..MatchTextExactly = True
has no effect on how it matches filenames. This setting has to do with
looking for a string contained in the file itself. Filesearch does not do a
match text exactly, so you just need to loop through the results and see if
one of the results is the file you want.

sStr1 = "excel.exe"
set fs = Application.FileSearch
With fs
.NewSearch
.FileName = sStr1
.LookIn = "C:\Program Files"
.SearchSubFolders = True
.MatchTextExactly = True
.FileType = msoFileTypeAllFiles
End With
fs.Execute

sStr2 = ""
For r = 1 To fs.FoundFiles.Count
if instr(len(fs.foundfiles(r))-8,fs.FoundFiles(r),sStr1,vbTextCompare)
then
sStr2 = fs.FoundFiles(r)
fr = r
end if
Next r
if sStr2 < "" then
msgbox fs.FoundFiles(fr) & " was found"
End If

--
Regards,
Tom Ogilvy




Stephen Allen wrote in message
...
The following code gives a found files count of 3 where only 1 file
exists.
set fs = Application.FileSearch
With fs
.NewSearch
.FileName = "EXCEL.exe"
.LookIn = "C:\Program Files"
.SearchSubFolders = True
.MatchTextExactly = True
.FileType = msoFileTypeAllFiles
End With
fs.Execute

For r = 1 To fs.FoundFiles.Count
MsgBox fs.FoundFiles(r)
Next r


The MsgBox refers to the same file each time "C:\Program
Files\Micrsoft Office\Office\EXCEL.exe"

Any thoughts on how to refine the code to give the expected answer?



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Lookup returns unexpected result David Ryan Excel Worksheet Functions 4 April 2nd 09 09:35 PM
Unexpected Result Hardeep_kanwar[_2_] Excel Worksheet Functions 2 January 16th 09 03:29 PM
Unexpected Result with "If" Logic/Conditional Statement Bill Ridgeway Excel Discussion (Misc queries) 1 July 3rd 07 07:07 PM
FV Function result is unexpected. RushatiINDIA Excel Worksheet Functions 8 February 28th 07 03:13 AM
Unexpected result Biff Excel Worksheet Functions 5 June 3rd 05 02:56 AM


All times are GMT +1. The time now is 12:53 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"