Howdy.
I'm new to VB.net, but not to programming....
Is there a simple way to search a hard drive for a specific file type?
Seems like it would be a common thing, yet I'm not having much luck finding anything...
Thanks in advance!
Howdy.
I'm new to VB.net, but not to programming....
Is there a simple way to search a hard drive for a specific file type?
Seems like it would be a common thing, yet I'm not having much luck finding anything...
Thanks in advance!
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Don WoodmanPosted Sep 15, 2007, 11:22 PM
Thanks, Scott. You've got me going. I am having problems when searching at the
root directory. When I do, I get errors when my program comes to either the recycler or
system voloume information.
How to get around?
Don
Scott LyslePosted Sep 2, 2007, 11:01 PM
Don:
Import System.IO and use the Directory.GetFiles methods. You can pass the method a search path and search pattern as arguments and it will return a string array containing the matching files. In the context of a console mode application, refer to the following for an example, in it, a string array called "files" is created and populated using the Directory.GetFiles call which is passed a search path (C:\Windows) and a search pattern (all executables (*.exe)).
Sub Main() Dim files() As String files = Directory.GetFiles("C:\Windows", "*.exe") Console.WriteLine() Console.WriteLine("Found " & files.Length & " EXE files") Dim file As String For Each file In files Console.WriteLine(file) Next 'wait Console.ReadLine() End Sub