Solved

Searching for a file.

Posted on 1998-11-10
5
152 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses
Course of the Month4 days, left to enroll

630 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