file search in VB.net

Hello everyone,

is there a simple way to search for a specific file in a directory which has sub directories.

for example if I had a file called test.dft (solidedge). I want to find it and get the path location any help would be great

thanks

Paul Martz

National Steel Car

 

Posted by: Paul Martz
Post date: 11/25/2005 4:12:29 AM

6 REPLIES

RE: file search in VB.net

 

 

Imports System.IO

 

Module Module1

 

Sub Main()

FindFile("test.dft", New DirectoryInfo("C:\"))

End Sub

 

Private Sub FindFile(ByVal fileName As String, ByVal objFolder As DirectoryInfo)

Dim objFiles() As FileInfo

Dim objSubfolders() As DirectoryInfo

 

objFiles = objFolder.GetFiles(fileName)

For Each objFile As FileInfo In objFiles

Console.WriteLine(objFile.FullName) '

Next

 

objSubfolders = objFolder.GetDirectories()

For Each objSubfolder As DirectoryInfo In objSubfolders

FindFile(fileName, objSubfolder)

Next

End Sub

 

End Module

 

 

Posted by: Jason Newell
Post date: 11/27/2005 1:29:28 PM

RE: file search in VB.net

Thanks Jason,

I have been pushing through this VB.Net stuff, its frustrating when processes work in VB6, but have to approach it differently in .net.

 

Another question, sample code that you gave me is for a module. I want to access this through my form with a button, I am having trouble getting this to work. Imports system.IO I figured out. Any guidance would be great

thanks

Paul

 

Posted by: Paul Martz
Post date: 11/28/2005 1:01:19 AM

RE: file search in VB.net

Sorry, I figured it out

thanks again

Paul

 

Posted by: Paul Martz
Post date: 11/28/2005 1:10:23 AM

RE: file search in VB.net

Jason,

I want to to take the objfile.fullname(once found) and save it to a string, I have been trying this, and it alway wipes out the value and keeps looping, I've tried early exits and it just keeps clearing the string values. Basically it want to push the string back to the form to use that value for other parts of the program.

Thanks

Paul

 

Posted by: Paul Martz
Post date: 11/28/2005 4:34:13 AM

RE: file search in VB.net

Paul,

 

I attached a VB.NET demo to do what you're wanting. This windows app looks and works a little like Windows 2000 search. I added some commented out code for you that allows you to find the 1st file and exit out of the recursive sub routine. Let me know if you still have any questions.

 

Posted by: Jason Newell
Post date: 11/28/2005 5:22:11 AM

RE: file search in VB.net

thanks again Jason

Paul

 

Posted by: Paul Martz
Post date: 11/28/2005 7:39:44 AM