Results 1 to 9 of 9
  1. #1
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 16 Times in 16 Posts

    Re: File Search and Shurtcuts (office 97, XP & VB6)

    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

  2. Subscribe to our Windows Secrets Newsletter - It's Free!

    Get our unique weekly Newsletter with tips and techniques, how to's and critical updates on Windows 7, Windows 8, Windows XP, Firefox, Internet Explorer, Google, etc. Join our 480,000 subscribers!

    Excel 2013: The Missing Manual

    + Get this BONUS — free!

    Get the most of Excel! Learn about new features, basics of creating a new spreadsheet and using the infamous Ribbon in the first chapter of Excel 2013: The Missing Manual - Subscribe and download Chapter 1 for free!

  3. #2
    2 Star Lounger
    Join Date
    Mar 2001
    Location
    Emerald Beach, New South Wales, Australia
    Posts
    126
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: File Search and Shurtcuts (office 97, XP & VB6)

    Hans,

    Thank you. There is nothing like a simplistic solution to fix things, I will give it a go. <img src=/S/blush.gif border=0 alt=blush width=15 height=15>

    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

  4. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 16 Times in 16 Posts

    Re: File Search and Shurtcuts (office 97, XP & VB6)

    It's a bug - no, it's a feature of FileSearch. <img src=/S/blackteeth.gif border=0 alt=blackteeth width=20 height=20>

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

  5. #4
    Star Lounger
    Join Date
    Jan 2001
    Posts
    71
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: File Search and Shurtcuts (office 97, XP & VB6)

    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

  6. #5
    2 Star Lounger
    Join Date
    Mar 2001
    Location
    Emerald Beach, New South Wales, Australia
    Posts
    126
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: File Search and Shurtcuts (office 97, XP & VB6)

    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

  7. #6
    2 Star Lounger
    Join Date
    Mar 2001
    Location
    Emerald Beach, New South Wales, Australia
    Posts
    126
    Thanks
    0
    Thanked 0 Times in 0 Posts

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

    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



    <pre> 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.......
    </pre>


  8. #7
    Star Lounger
    Join Date
    Jan 2001
    Posts
    71
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: File Search and Shurtcuts (office 97, XP & VB6)

    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.

  9. #8
    2 Star Lounger
    Join Date
    Mar 2001
    Location
    Emerald Beach, New South Wales, Australia
    Posts
    126
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: File Search and Shurtcuts (office 97, XP & VB6)

    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

  10. #9
    Star Lounger
    Join Date
    Jan 2001
    Posts
    71
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: File Search and Shurtcuts (office 97, XP & VB6)

    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...

Posting Permissions

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