narmi2
asked on
Simple File Search
Hi
I would like to search my FULL hard drive "C:\" and list all files with the extension ".doc". These files could be in the root of "C:\" or in directories or sub directories. It should search in all sub directories to all depths and all the matching extension paths and filename in a listview.
Does anyone know how to do this?
Thanks
I would like to search my FULL hard drive "C:\" and list all files with the extension ".doc". These files could be in the root of "C:\" or in directories or sub directories. It should search in all sub directories to all depths and all the matching extension paths and filename in a listview.
Does anyone know how to do this?
Thanks
ASKER
How would you do this with a listview? If the listview had 3 columns, how would i populate the listviews columns like this
col1 - Full Path
col2 - File Name
col3 - Extension
col1 - Full Path
col2 - File Name
col3 - Extension
ASKER
Ok I got the following
-------------------------- ----------
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
GetSubdirectoriesAndFiles( System.IO. Directory. GetDirecto ries("C:\" ), ListView1) '// Change to your path
End Sub
Sub GetSubdirectoriesAndFiles( ByVal directory() As String, ByVal lv As ListView)
Dim MyCountSearch As Integer = 1
Dim Dir As String
Dim lv2 As ListViewItem
For Each Dir In directory
Dim Files() As String = System.IO.Directory.GetFil es(Dir, "*")
Dim File As String
Dim Dirc As String
For Each File In Files
If Path.GetFileName(File).End sWith(".do c") Or Path.GetFileName(File).End sWith(".DO C") Then
lv2 = New ListViewItem
lv2.Text = Path.GetFullPath(File)
lv2.SubItems.Add(Path.GetF ileName(Fi le))
lv2.SubItems.Add(Path.GetE xtension(F ile))
lv.Items.Add(lv2)
End If
Next
GetSubdirectoriesAndFiles( System.IO. Directory. GetDirecto ries(Dir), lv)
Next
End Sub
-------------------------- ---------- ---
But this misses out all the .doc files in the root of C:\ ???
How do I search the root also?
Thanks
--------------------------
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
GetSubdirectoriesAndFiles(
End Sub
Sub GetSubdirectoriesAndFiles(
Dim MyCountSearch As Integer = 1
Dim Dir As String
Dim lv2 As ListViewItem
For Each Dir In directory
Dim Files() As String = System.IO.Directory.GetFil
Dim File As String
Dim Dirc As String
For Each File In Files
If Path.GetFileName(File).End
lv2 = New ListViewItem
lv2.Text = Path.GetFullPath(File)
lv2.SubItems.Add(Path.GetF
lv2.SubItems.Add(Path.GetE
lv.Items.Add(lv2)
End If
Next
GetSubdirectoriesAndFiles(
Next
End Sub
--------------------------
But this misses out all the .doc files in the root of C:\ ???
How do I search the root also?
Thanks
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Your method looks better than the one i posted. Give me a few moments to test it out! :D
ASKER
That's perfect!
Thanks! :D
Thanks! :D
:^)
Good luck with the rest of your project(s)
Dave
Good luck with the rest of your project(s)
Dave
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
GetSubdirectoriesAndFiles(
End Sub
Sub GetSubdirectoriesAndFiles(
Dim di As New System.IO.DirectoryInfo(di
For Each fi As System.IO.FileInfo In di.GetFiles()
If fi.Extension = ".doc" Then
Me.ListBox1.Items.Add(fi.F
End If
Next
For Each dir As System.IO.DirectoryInfo In di.GetDirectories()
GetSubdirectoriesAndFiles(
Next
End Sub
Dave