Recursive Search using the FileSystemObject Model : FileSystemObject « File Path « VBA / Excel / Access / Word

VBA / Excel / Access / Word
1. Access
2. Application
3. Data Type
4. Data Type Functions
5. Date Functions
6. Excel
7. File Path
8. Forms
9. Language Basics
10. Math Functions
11. Outlook
12. PowerPoint
13. String Functions
14. Windows API
15. Word
16. XML
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
VBA / Excel / Access / Word » File Path » FileSystemObject 
Recursive Search using the FileSystemObject Model
 
Private Sub cmdStartSearch_Click()
    Call FindFile("yourFile""C:\", False)
    Unload frmSearch
End Sub

Private Sub FindFile(target As String, ByVal aPath As String, foundTarget As Boolean)
    Dim myFileSystemObject As FileSystemObject, curFolder As folder, folder As folder
    Dim folColl As Folders, file As file, fileColl As Files
    Set myFileSystemObject = New FileSystemObject
    Set curFolder = myFileSystemObject.GetFolder(aPath)
    Set folderList = curFolder.SubFolders
    Set fileList = curFolder.Files

    For Each file In fileList
        If file.name = target Then
            foundTarget = True
            frmFileSystem.lblPath.Caption = file.Path
            Exit Sub
        End If
    Next

    If Not foundTarget Then
        For Each folder In folderList
            DoEvents        'Yield execution so other events may be processed
            If Not foundTarget Then
                 FindFile target, folder.Path, foundTarget
            End If
        Next
    End If
    Set myFileSystemObject = Nothing
    Set curFolder = Nothing
    Set folderList = Nothing
    Set fileList = Nothing
End Sub

 
Related examples in the same category
1. Copying a File
2. Display selected file information
3. Delete file by using FileSystemObject
4. Delete Folder by using FileSystemObject
5. Listing files with a For...Each loop
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.