Solved

Searching for a file.

Posted on 1998-11-10
5
151 Views
Last Modified: 2012-05-04
Does anybody know of a function that will search the
c: drive for a file and return the full path to it?
0
Comment
Question by:cybergirl
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 2

Accepted Solution

by:
dabellei earned 40 total points
ID: 1444075
go to http://www.vb-word.net/tips/tip59.html

There a demo on how using API to search for file on a drive.

0
 
LVL 2

Expert Comment

by:dabellei
ID: 1444076
0
 
LVL 9

Expert Comment

by:Dalin
ID: 1444077
Public Function fFindthePath(ByVal startDir As String, ByVal myFileName As String) As String
Dim dir_names() As String
Dim num_dirs As Integer
Dim i As Integer
Dim fname As String
Dim new_files As String
Dim attr As Integer
Dim theDir As String
Dim theSubDir As String

    On Error Resume Next
   
    ' See If the file in this directory.
  If Right(startDir, 1) = "\" Then startDir = Left(startDir, Len(startDir) - 1)
    theDir = startDir & "\"
    fname = Dir(theDir & myFileName, vbNormal)
    If fname <> "" Then
        fFindthePath = theDir
        Exit Function
    End If
   
     
    ' Not find in the main dir, Get the list of subdirectories.
    fname = Dir(startDir & "\*.*", vbDirectory)
    Do While fname <> ""
        ' Skip this dir and its parent.
        attr = 0    ' In case there's an error.
        attr = GetAttr(startDir & "\" & fname)
        If fname <> "." And fname <> ".." And _
            (attr And vbDirectory) <> 0 _
        Then
            num_dirs = num_dirs + 1
            ReDim Preserve dir_names(1 To num_dirs)
            dir_names(num_dirs) = fname
        End If
        fname = Dir()
    Loop
   
    ' Search the other directories.
    For i = 1 To num_dirs
        theSubDir = fFindthePath(startDir & "\" & dir_names(i), myFileName)
        If theSubDir > "" Then
            fFindthePath = theSubDir
            Exit Function
        End If
    Next i

End Function
0
 
LVL 9

Expert Comment

by:Dalin
ID: 1444078
to call, pass the parameter:
Dim lstring as String
lString = fFindthePath("C:\", theFileName)
0
 

Author Comment

by:cybergirl
ID: 1444079
Thanks...it worked great.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question