CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Jul 2001
    Posts
    12

    How can I search Files in Drives and get it's Path?

    I'd like to get the Path of a file in a Drive.
    For Ex.
    FileName = "Northwind.mdb"
    I'd like to know the exact path of where Northwind.mdb is in my "C:" Hard Drive
    or my "D:" Mapped Network Drive.
    I need to get the exact path so that I can point to that Database and Compact
    that Database.
    I'm trying to make an Access .mdb that will compact another .mdb Database.
    I'm able to do this but I have a problem with setting the Path of the Database
    to Compact.

    In Access CurDir() does not work because it always has "My Documents" as its value.



  2. #2
    Join Date
    Jan 2000
    Location
    Olen, Belgium
    Posts
    2,477

    Re: How can I search Files in Drives and get it's Path?

    I think this is just what you need
    http://www.vb-world.net/files/tip529.html


    Tom Cannaerts
    [email protected]

    Programming today is a race between software engineers striving to build bigger and better idot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook
    Tom Cannaerts
    email: [email protected]
    www.tom.be (dutch site)

  3. #3
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    Re: How can I search Files in Drives and get it's Path?

    Just to add to Cakkie answer.
    If you need only path (withoy the file name) then use the following code

    Private Function GetModelPath(ByVal flname As String)
    '=============================================================================
    Dim sPath As String
    Dim i As Integer
    Dim sTemp As String

    sTemp = flname

    For i = 1 To Len(flname)
    If Right(sTemp, 1) = "\" Then
    GetModelPath = sTemp
    Exit For
    Else
    sTemp = Left(flname, Len(flname) - i)
    End If
    Next i


    End Function


    Iouri Boutchkine
    [email protected]
    Iouri Boutchkine
    [email protected]

  4. #4
    Join Date
    Jul 2001
    Posts
    12

    Re: How can I search Files in Drives and get it's Path?

    Thanks for the Reply, I really appreciate it.

    I'll try the code and see if it works.
    I'd like to ask if you know a substitute for CurDir() in MS Access,
    I'm having problems with this. In VB it gives the correct path if
    you use CurDir() like if you're current directory is "c:\Program Files/Programs"
    then it will display that Path, but in Access it always show "C:\My Documents".
    Thanks


  5. #5
    Join Date
    Jul 2001
    Posts
    12

    Re: How can I search Files in Drives and get it's Path?

    Thanks, I've checked the code and used it and it works. But I was wondering if it's possible to get all of the occurences of the file in the Drive.
    Ex. "vb.exe" is located in "C:\Program Files\vb.exe", "C:\My Documents\vb.exe",
    "D:\Projects\vb.exe", "E:\Installers\vb.exe", etc.
    Thanks!


  6. #6
    Join Date
    Jan 2000
    Location
    Olen, Belgium
    Posts
    2,477

    Re: How can I search Files in Drives and get it's Path?

    http://www.vb-world.net/files/findfiles/
    This is another way to do that, this finds all the files, just change the *.* into whatever you need.

    Note: the Dir version doesn't work correctly on NT4

    Tom Cannaerts
    [email protected]

    Programming today is a race between software engineers striving to build bigger and better idot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook
    Tom Cannaerts
    email: [email protected]
    www.tom.be (dutch site)

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured