Click to See Complete Forum and Search --> : folder, subfolders, and text files


pantea
05-24-2005, 03:01 PM
Hi everyone :WAVE: ,
I copied one folder which contain some subfolders and after few layers of subfolders there are some text files that i want to parse. for example:
my main folder is: My_Main_folder then inside it there are My_sub_one, my_sub_some, ..... then again inside these subs could be more subs until some where there are some txt file at each sub
is there any easy approch to open My_Main_folder and all subs and just read txt files.

Appreciate your help

kmoorman
05-24-2005, 03:20 PM
pantea,

Here is a sub that accepts a folder name and then displays any text files in that folder and in any subfolders of that folder:

Private Sub DisplayFiles(ByVal folder As String)

Dim di As New DirectoryInfo(folder)
Dim fi As FileInfo

For Each fi In di.GetFiles
If fi.Extension = ".txt" Then
MsgBox("File: " & fi.FullName)
End If
Next

Dim subDI As DirectoryInfo
For Each subDI In di.GetDirectories
DisplayFiles(di.FullName & "\" & subDI.Name)
Next

End Sub

Call the sub like this:

DisplayFiles("E:\Test Folder")
MsgBox("Done")

Kerry Moorman

pantea
05-24-2005, 03:36 PM
thank you it worked perfect