• File Search and Shortcuts (office 97, XP & VB6)

    Home » Forums » AskWoody support » Productivity software by function » Visual Basic for Applications » File Search and Shortcuts (office 97, XP & VB6)

    Author
    Topic
    #408468

    You can test if the found files are shortcuts by looking at their extension:

    With appAccess.FileSearch

    For i = 1 To .FoundFiles.Count
    If LCase(Right(.FoundFiles(i), 3)) = “lnk” Then
    ‘ Shortcut – ignore
    Else
    ‘ Code to process file goes here

    End If
    Next i

    End With

    Viewing 3 reply threads
    Author
    Replies
    • #862748

      Hans,

      Thank you. There is nothing like a simplistic solution to fix things, I will give it a go. blush

      Why a shortcut is returned still bothers me though. Do you have any idea why a filespec of *.mdb should return *.mdb and *.lnk where the target of the shortcut is a mdb?

      Is it possible to have a filespec with an exclusion eg *.mdb;*.mde;-*.lnk ?

      Cheers

      Stewart

      • #862754

        It’s a bug – no, it’s a feature of FileSearch. blackteeth

        Lots of complaints about it in the newsgroups. I don’t think you can exclude file types the way you suggest.

      • #862755

        It’s a bug – no, it’s a feature of FileSearch. blackteeth

        Lots of complaints about it in the newsgroups. I don’t think you can exclude file types the way you suggest.

      • #863207

        FileSearch sucks. Here’s some code that does what you want: include or exclude file specs:
        http://vbnet.mvps.org/code/fileapi/recursi…leselective.htm%5B/url%5D

        • #863263

          Don,

          That code absolutely screams. It had a bug that stoped it from returning any results but once I fixed that it took 5.71 seconds to run over my hard drive where filesearch took over 40seconds.

          It still returned the lnk files but I added a second excluded filespec check and in 7.46 seconds it returns exactly what I needed.

          Apart from solving my immediate problem you have provided me with a wonderful resource.

          Thank you.

          Stewart

          • #863795

            There are quite a few ways to optimize that code even further, but I’m sure you’ve found those tweaks yourself…
            I’m thinking of turning it into a class, and see what the speed advantage/penalty would be.

            • #863799

              To be honest Don,

              I’m a regular VB neophyte, I come from the land of access where dealing with files isn’t really a big part of it all.

              I was amazed at the simplicity of the code and honestly don’t see where it could be optimised further.

              Is there any reason that you would expect a class to be faster?
              I’m guessing here but is it because you don’t need to re initalise all the variables, just delcare a new instance of a filesearch object and keep throwing folders at it or would you throw file specs?

              Stewart

            • #864232

              I’m not sure a class would be faster, but it would make the programming easier. I’ll play with that when I have time…
              I think the original code would be more efficient if the PathMatchSpec function would be declared to return a Booleran lather than a Long, so you could have the bFindOrExclude value be a Boolean, too. Also, the QualifyPath function could be made more efficient, by using a Like operator (If Path like “*/”). Computers love Booleans, so the less string manipulation you use, the better.
              Anyway, I’ll come back to this thread when I’ve done some more research…

            • #864233

              I’m not sure a class would be faster, but it would make the programming easier. I’ll play with that when I have time…
              I think the original code would be more efficient if the PathMatchSpec function would be declared to return a Booleran lather than a Long, so you could have the bFindOrExclude value be a Boolean, too. Also, the QualifyPath function could be made more efficient, by using a Like operator (If Path like “*/”). Computers love Booleans, so the less string manipulation you use, the better.
              Anyway, I’ll come back to this thread when I’ve done some more research…

            • #863800

              To be honest Don,

              I’m a regular VB neophyte, I come from the land of access where dealing with files isn’t really a big part of it all.

              I was amazed at the simplicity of the code and honestly don’t see where it could be optimised further.

              Is there any reason that you would expect a class to be faster?
              I’m guessing here but is it because you don’t need to re initalise all the variables, just delcare a new instance of a filesearch object and keep throwing folders at it or would you throw file specs?

              Stewart

          • #863796

            There are quite a few ways to optimize that code even further, but I’m sure you’ve found those tweaks yourself…
            I’m thinking of turning it into a class, and see what the speed advantage/penalty would be.

        • #863264

          Don,

          That code absolutely screams. It had a bug that stoped it from returning any results but once I fixed that it took 5.71 seconds to run over my hard drive where filesearch took over 40seconds.

          It still returned the lnk files but I added a second excluded filespec check and in 7.46 seconds it returns exactly what I needed.

          Apart from solving my immediate problem you have provided me with a wonderful resource.

          Thank you.

          Stewart

      • #863208

        FileSearch sucks. Here’s some code that does what you want: include or exclude file specs:
        http://vbnet.mvps.org/code/fileapi/recursi…leselective.htm%5B/url%5D

    • #862749

      Hans,

      Thank you. There is nothing like a simplistic solution to fix things, I will give it a go. blush

      Why a shortcut is returned still bothers me though. Do you have any idea why a filespec of *.mdb should return *.mdb and *.lnk where the target of the shortcut is a mdb?

      Is it possible to have a filespec with an exclusion eg *.mdb;*.mde;-*.lnk ?

      Cheers

      Stewart

    • #862726

      Subject edited to correct spelling error, this will assist future lounge searches. StuartR
      Hi all,

      I’m using the filesearch object to build a list of files in a specified location.

      I discovered today that if there there are shortcuts to file types that are included in the filespec, the shortcut targets are included in the search results despite the shortcut having lnk extension. To me this doesn’t make sense.

      Does anyone know how to exclude shortcuts or identify when looking at the foundfiles collection that it was a link not a physical file?

      Thanks

      Stewart

          With appAccess.FileSearch
              .NewSearch
              .LookIn = Me.txtSelectLocation
              If chkSubFolders = 1 Then
                  .SearchSubFolders = True
              Else
                  .SearchSubFolders = False
              End If
              If Me.chkWord = 1 Then
                  strFileSelected = strFileSelected & "*.DOC;*.DOT;"
              End If
              If Me.ChkExcel = 1 Then
                  strFileSelected = strFileSelected & "*.XLS;*.XLA;*.XLT;*.XLL;"
              End If
              If Me.ChkAccess = 1 Then
                  strFileSelected = strFileSelected & "*.MDB;*.MDE;*.MDW;*.MDA;*.MDZ;*.MDT;"
              End If
              If Not strFileSelected = "" Then
                  .FileName = strFileSelected
              Else
                  MsgBox "You Must Select File Types to Scan" & " - " & "No FileSpec Selected"
                  Me.lblFiles.Caption = 0
                  GoTo Proc_Exit
              End If
              If .Execute  0 Then
        etc etc.......
      
    • #862727

      Subject edited to correct spelling error, this will assist future lounge searches. StuartR
      Hi all,

      I’m using the filesearch object to build a list of files in a specified location.

      I discovered today that if there there are shortcuts to file types that are included in the filespec, the shortcut targets are included in the search results despite the shortcut having lnk extension. To me this doesn’t make sense.

      Does anyone know how to exclude shortcuts or identify when looking at the foundfiles collection that it was a link not a physical file?

      Thanks

      Stewart

          With appAccess.FileSearch
              .NewSearch
              .LookIn = Me.txtSelectLocation
              If chkSubFolders = 1 Then
                  .SearchSubFolders = True
              Else
                  .SearchSubFolders = False
              End If
              If Me.chkWord = 1 Then
                  strFileSelected = strFileSelected & "*.DOC;*.DOT;"
              End If
              If Me.ChkExcel = 1 Then
                  strFileSelected = strFileSelected & "*.XLS;*.XLA;*.XLT;*.XLL;"
              End If
              If Me.ChkAccess = 1 Then
                  strFileSelected = strFileSelected & "*.MDB;*.MDE;*.MDW;*.MDA;*.MDZ;*.MDT;"
              End If
              If Not strFileSelected = "" Then
                  .FileName = strFileSelected
              Else
                  MsgBox "You Must Select File Types to Scan" & " - " & "No FileSpec Selected"
                  Me.lblFiles.Caption = 0
                  GoTo Proc_Exit
              End If
              If .Execute  0 Then
        etc etc.......
      
    Viewing 3 reply threads
    Reply To: File Search and Shortcuts (office 97, XP & VB6)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: