Visual Basic > Files Directories Drives
Find a file on a drive-path
Find a file on a drive-path 'check if file exist and when found show the location 'btw: it will only find the first one! 'just change the code to find all 'use as: 'MsgBox FindFile("c:\", vFile$) & vFile$ Public Function FileExist(Path$) as Integer dim x x = FreeFile On Error Resume Next open Path$ For input as x If Err = 0 Then FileExist = True Else FileExist = False end If close x End Function Public Function FindFile(ByVal Path as String, ByVal File as String) as String dim DirName as String, LastDir as String If File = "" Then exit Function If Right(Path, 1) <> "\" Then Path = Path & "\" DirName = Dir(Path & "*.*", vbDirectory) do While Not FileExist(Path & File) If DirName = "" Then exit Do DoEvents If DirName <> "." And DirName <> ".." Then If (GetAttr(Path & DirName) And vbDirectory) = vbDirectory Then LastDir = DirName DirName = FindFile(Path & DirName & "\", File) If DirName <> "" Then Path = DirName exit Do end If DirName = Dir(Path, vbDirectory) do Until DirName = LastDir Or DirName = "" DirName = Dir Loop If DirName = "" Then exit Do end If end If DirName = Dir Loop If FileExist(Path & File) Then FindFile = Path End Function Return
Visual Basic Codes
ActiveX
Miscellaneous
Applications
Code Snippets
Common Dialogs
Special Effects
Database Stuff
Date Time
Files Drives
Forms
Graphics Games
Internet Stuff
Multimedia
Other
Strings
Windows