Results 1 to 5 of 5

Thread: file search

  1. #1
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740

    Unanswered: file search

    looking for ideas/hints: i want A to search a defined drive and return the path for a given name.ext

    i.e. the A-VBA equivalent of DOS:
    DIR C:\MYFILE.TXT /S

    izy
    currently using SS 2008R2

  2. #2
    Join Date
    Jan 2004
    Location
    Jersey, UK
    Posts
    108
    Iddy, I think this might help.

    http://www.microsoft-accesssolutions.co.uk/modules.htm

    Check out the downloadable db that pops up the common dialog (file open). If you take a look at the module in this db, you can see where/how the code looks at a network path and pops up the dialog box with file extension filters.

    I reckon with some tweaking you should be able to use this to search for a file.


    Andy

  3. #3
    Join Date
    Nov 2003
    Posts
    1,487
    Use the FindFirstFile, FindNextFile, and FindClose API functions.


  4. #4
    Join Date
    Nov 2003
    Posts
    43
    To return the path for a given .ext use the API FindExecutable.

    This API recognizes the associated application. ACtually it will return the whole path.

    Exemple :

    Code:
    Private Declare Function FindExecutable Lib "shell32.dll" Alias "FindExecutableA" ( _
    ByVal lpFile As String, _
    ByVal lpDirectory As String, _
    ByVal lpResult As String) As Long


    Private Sub Command1_Click()
    Dim Appli As String
    Dim answer As Long
    Appli = Space$(250)
    answer = FindExecutable("Texte.txt", "C:\Mes Documents", Appli)
    Appli = Left$(Appli, InStr(1, Appli, vbNullChar) - 1)
    MsgBox Appli
    End Sub


    On my pc, Appli = C:\Windows\Notpad.exe

    Now if you're only looking for a file and not the associated application then you can use this code;

    Dim I As Long
    With Application.FileSearch
    .FileName = "MonFichier.txt"
    .LookIn = "C:\"
    .SearchSubFolders = True
    .Execute
    With .FoundFiles
    For I = 1 To .Count
    MsgBox .Item(I)
    Next I
    End With
    End With

    Hope that helps !!


    Chiron

  5. #5
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740

    auto-set references

    thanks for the nudge in the direction of APIs - why didn't i think of that! my API book is from 1993 so some www research was necessary.

    i decided to go with imagehlp for simplicity.

    in case it is of interest, i attach a ZIPped MDB

    with form utilityLibLoad as the startup form, an application will check that "unusual" libraries are referenced (if necessary scanning the disk for the file and adding the reference). in the ZIPped example, DAO & Outlook libraries are checked/set.

    it takes a looooong time the first time around as it scans c: for the file(s) - after the libraries are referenced the utility form only takes a fraction of a second to check references and unload, then load the "real" application startup form as defined by Const frmOpen

    my disk scan could probably be smartened up a bit, but since this is a one-time process it hardly seems worth the effort.

    thanks to the several people here who contributed code snippets.

    izy
    currently using SS 2008R2

Posting Permissions

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