Results 1 to 3 of 3

Thread: Finding files

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2000
    Location
    W.Lafayette, In USA
    Posts
    37
    Does anyone have code that can find a file at an unknown
    location on a drive. Please I really need your help. Thanks in advance.

  2. #2
    Lively Member Ishamel's Avatar
    Join Date
    Nov 1999
    Location
    Edinburgh, Scotland
    Posts
    112
    This code will scroll through all of the directories/sub-directories in the C Drive looking for a file call "myFile.TXT"

    (This code uses the FileSystemObject so you will have to remember and reference the Microsoft Scripting Runtime library in your project.)

    Code:
    Dim m_objFSO As Scripting.FileSystemObject
    
    Private Sub Command1_Click()
        Set m_objFSO = New Scripting.FileSystemObject
        
        Screen.MousePointer = vbHourglass
        
        Call CheckFolder("C:\")
        
        Screen.MousePointer = vbDefault
    End Sub
    
    Public Sub CheckFolder(sPath As String)
    
        Dim objFolder As Scripting.Folder
        Dim objSubDirs As Scripting.Folders
        Dim objLoopFolder As Scripting.Folder
        Dim myItem As String
        
        Set objFolder = m_objFSO.GetFolder(sPath)
        
        'Does the sPath string require an extra back-slash?
        If Right(sPath, 1) <> "\" Then sPath = sPath & "\"
        
        If (m_objFSO.FileExists(sPath & "myFile.TXT")) Then
            msgbox "File exists in directory : " & sPath
        End If
        
        Set objSubDirs = objFolder.SubFolders
        
        'Repeat this Sub for each sub directory in
        'the SubFolders collection
        For Each objLoopFolder In objSubDirs
            CheckFolder objLoopFolder.Path
        Next objLoopFolder
        
        'Free up memory
        Set objSubDirs = Nothing
        Set objFolder = Nothing
    End Sub
    Hope this helps.

  3. #3
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238
    I have write a file searching utility with the FinfFirstFile and FindNExtFile Win32 API function. If you interested, then just email me & I'll forward it to you.


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