lilgirl Posted July 30, 2003 Posted July 30, 2003 I know the name of the file I want to open and I know the root directory it is located in. It is simple to open the file if i know which subdirectory it is in, but my question is: how do I search the root directory and any subdirectories for the file and then open it? Quote
Madz Posted July 30, 2003 Posted July 30, 2003 You need to implement a FOR Loop that checks all direcotries and use this method FILE.Exists(FileName) this has a boolean value if files exists then stop search other wise go to next directory Quote The one and only Dr. Madz eee-m@il
Hughng Posted July 30, 2003 Posted July 30, 2003 (edited) Try this. I have not debug it yet. Basically, it just index through all your subdirectories until find the file that ended with your extention. You might have to fix up some syntax error as I don't have a compiler to check the code at this time :-). =================================== Private Function FindFile(ByVal tDir As String, ByVal tFile as String) as String Try Dim strResult as string Dim fInfo As FileInfo Dim dInfo As New DirectoryInfo(tDir) Dim subDir() As DirectoryInfo Dim tCount As Integer For Each fInfo In dInfo.GetFiles if fInfo.FullName.EndWith(tFile) Return dInfo.FullName Next subDir = dInfo.GetDirectories() For tCount = 0 To subDir.Length - 1 strResult = FindFile(subDir(tCount).FullName) If strResult <> Nothing return strResult Next Catch Exp As Exception MsgBox("Exception: " & Exp.Message) End Try return strResult End Sub ======================================== Edited July 30, 2003 by Hughng Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.