Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    Silver Lounger
    Join Date
    Mar 2001
    Location
    Springfield, Ohio, USA
    Posts
    2,136
    Thanks
    0
    Thanked 1 Time in 1 Post

    Office FileSearch Object (Office 2000)

    Is it possible to force the Office.FileSearch object to find an exact match? In my case, I'm looking for xvt.h but ixvt.h, noxvt.h, and xvt.h are returned, so I have to look at all of the .FoundFiles to find the correct one. I would rather just always use .FoundFiles(1). TIA --Sam
    <font face="Comic Sans MS">Sam Barrett, CACI </font face=comic>
    <small>And the things that you have heard... commit these to faithful men who will be able to teach others also. 2 Timothy 2:2</small>

  2. #2
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Office FileSearch Object (Office 2000)

    Does this property offer any relief:

    .MatchTextExactly = True

    ??
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  3. #3
    Silver Lounger
    Join Date
    Mar 2001
    Location
    Springfield, Ohio, USA
    Posts
    2,136
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Office FileSearch Object (Office 2000)

    Nope!
    <font face="Comic Sans MS">Sam Barrett, CACI </font face=comic>
    <small>And the things that you have heard... commit these to faithful men who will be able to teach others also. 2 Timothy 2:2</small>

  4. #4
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Dublin, Ireland, Republic of
    Posts
    2,697
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Office FileSearch Object (Office 2000)

    Sammy did you include

    With Application.FileSearch
    ..............
    ..............
    .Filename = "xvt.h"



    Andrew C

  5. #5
    Silver Lounger
    Join Date
    Mar 2001
    Location
    Springfield, Ohio, USA
    Posts
    2,136
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Office FileSearch Object (Office 2000)

    Yep! I also realized that I had a "preferred" directory in case of duplicates, so I had to iterate through the .FoundFiles anyway. Here's what the code evolved to and now looking at it, it seems sort of dumb to use the Dir function and the File object. Oh well, it does what I want. Seems strange though that you cannot force an exact match. Thanks! --Sam
    <pre>Option Explicit
    Sub WhereIs()
    Const strPath = "c:My ProjectsNIMA_MUSEmuse"
    Dim fsSearch As Office.FileSearch
    Dim fso As New Scripting.FileSystemObject
    Dim f As Scripting.File
    Dim i As Integer
    Dim j As Integer
    For i = 1 To ActiveSheet.UsedRange.Rows.Count
    ActiveSheet.Cells(i, 2) = ""
    Set fsSearch = Application.FileSearch
    With fsSearch
    .NewSearch
    .LookIn = strPath
    .SearchSubFolders = True
    .Filename = ActiveSheet.Cells(i, 1).Text
    .MatchTextExactly = True
    If .Execute(SortBy:=msoSortByLastModified) > 0 Then
    For j = 1 To .FoundFiles.Count ' Look for exact match & if possible from comdline
    If Dir(.FoundFiles(j)) = ActiveSheet.Cells(i, 1).Text Then
    ActiveSheet.Cells(i, 2) = .FoundFiles(j)
    Set f = fso.GetFile(.FoundFiles(j))
    If f.ParentFolder.Name = "comdline" Then
    Exit For ' Found the one we were really looking for
    End If
    End If
    Next j
    End If
    End With
    Set fsSearch = Nothing
    Set f = Nothing
    Set fso = Nothing
    Next i
    End Sub
    </pre>

    <font face="Comic Sans MS">Sam Barrett, CACI </font face=comic>
    <small>And the things that you have heard... commit these to faithful men who will be able to teach others also. 2 Timothy 2:2</small>

  6. #6
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Office FileSearch Object (Office 2000)

    I confirm that this method works just as you indicate. Very strange.
    It seems to work like this:

    Like "*" & .filename & "*"

    no matter what you do.
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  7. #7
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Office FileSearch Object (Office 2000)

    <P ID="edit" class=small>(Edited by Kevin on 25-Oct-02 10:34. Never mind. It doesn't help.)</P>Sammy,

    Have to tried:

    .MatchAllWordForms = False

    ??
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  8. #8
    Silver Lounger
    Join Date
    Mar 2001
    Location
    Springfield, Ohio, USA
    Posts
    2,136
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Office FileSearch Object (Office 2000)

    No, I haven't tried it. Documentation doesn't look like it applies to the filename.
    <font face="Comic Sans MS">Sam Barrett, CACI </font face=comic>
    <small>And the things that you have heard... commit these to faithful men who will be able to teach others also. 2 Timothy 2:2</small>

  9. #9
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Office FileSearch Object (Office 2000)

    I clicked Post without verifying. Forgive me.

    I edited the orginal so as not to mislead the population at large.
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  10. #10
    3 Star Lounger
    Join Date
    Jun 2001
    Location
    Maidstone, Kent, England
    Posts
    398
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Office FileSearch Object (Office 2000)

    Just a thought, but in the normal search window you use quotes to get an exact match, could it be a case of wrapping your filename in quotes somehow?

    Peter

  11. #11
    Silver Lounger
    Join Date
    Mar 2001
    Location
    Springfield, Ohio, USA
    Posts
    2,136
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Office FileSearch Object (Office 2000)

    Well, I got excited with that idea! As you said, if I use "xvt.h" in an Explorer search, it dosn't list ixvt.h. But when I used
    <pre>.Filename = """xvt.h"""</pre>

    in code, it gave exactly the same results as
    <pre>.Filename = "xvt.h"</pre>

    ie, it included ixvt.h. <img src=/S/bummer.gif border=0 alt=bummer width=15 height=15>
    <font face="Comic Sans MS">Sam Barrett, CACI </font face=comic>
    <small>And the things that you have heard... commit these to faithful men who will be able to teach others also. 2 Timothy 2:2</small>

  12. #12
    3 Star Lounger
    Join Date
    Jun 2001
    Location
    Maidstone, Kent, England
    Posts
    398
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Office FileSearch Object (Office 2000)

    Was worth a try though <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

  13. #13
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: Office FileSearch Object (Office 2000)

    Just a thought and I don't know anything about this, but is there an equivalent to the 'find whole words only' option in ordinary search?
    Beryl M


  14. #14
    Silver Lounger
    Join Date
    Mar 2001
    Location
    Springfield, Ohio, USA
    Posts
    2,136
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Office FileSearch Object (Office 2000)

    No, there only is MatchAllWordForms and MatchTextExactly, and neither of these apply to the filename, but thanks!

    I did some more research on this and discovered that the implicit wildcard is a known problem, although some say that this is the way it should work. There is an API alternative, SearchTreeForFile in ImageHlp.dll. Quoting Dev Ashish:
    <pre>Private Declare Function apiSearchTreeForFile Lib "ImageHlp.dll" Alias _
    "SearchTreeForFile" (ByVal lpRoot As String, ByVal lpInPath _
    As String, ByVal lpOutPath As String) As Long

    Function fSearchFile(ByVal strFilename As String, _
    ByVal strSearchPath As String) As String
    'Returns the first match found
    Dim lpBuffer As String
    Dim lngResult As Long
    fSearchFile = ""
    lpBuffer = String$(1024, 0)
    lngResult = apiSearchTreeForFile(strSearchPath, strFilename, lpBuffer)
    If lngResult <> 0 Then
    If InStr(lpBuffer, vbNullChar) > 0 Then
    fSearchFile = Left$(lpBuffer, InStr(lpBuffer, vbNullChar) - 1)
    End If
    End If
    End Function</pre>

    <font face="Comic Sans MS">Sam Barrett, CACI </font face=comic>
    <small>And the things that you have heard... commit these to faithful men who will be able to teach others also. 2 Timothy 2:2</small>

  15. #15
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Office FileSearch Object (Office 2000)

    Sammy,
    Interesting that one needs to go to the ImageHlp.dll to get a file search function...

    Anyway, why is your file search need not fulfilled with a simple FileExists function?

    Since you only want the one file and you know the name... I'm puzzled.
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •