Solved

Searching for a file.

Posted on 1998-11-10
5
145 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
  • 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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

747 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now