[Vb.net] File Search?

Posts 1–7 of 7 · Page 1 of 1
[Vb.net] File Search?
Basically how would you search for a file on your C drive.

All i need is a listbox with the file path for each file found.

Btw i need a fast method as way.
The following code will search according to the pattern given. In this case .txt files:

[php] Dim searchAll As String = "*.*"
Dim searchSpecific As String = "*.txt"
For Each drive As DriveInfo In My.Computer.FileSystem.Drives
Try
For Each File As String In My.Computer.FileSystem.GetFiles(drive.Name, FileIO.SearchOption.SearchAllSubDirectories, searchSpecific )
Listbox1.Items.Add (File)
Next
Catch ex As Exception

'In case if a file's access is denied !!
Continue For
End Try
Next[/php]

Hope this helps !!
what if i want to search for txt file called database?
Quote Originally Posted by ppl2pass View Post
what if i want to search for txt file called database?
[php] Dim searchAll As String = "*.*"
Dim searchSpecific As String = "*.txt"
For Each drive As DriveInfo In My.Computer.FileSystem.Drives
Try
For Each File As String In My.Computer.FileSystem.GetFiles(drive.Name, FileIO.SearchOption.SearchAllSubDirectories, searchSpecific )
If system.io.path.getfilenamewithoutextension(File)=" database" Then
Listbox1.Items.Add (File)
End If
Next
Catch ex As Exception

'In case if a file's access is denied !!
Continue For
End Try
Next [/php]
it doesnt work for me.
is the file name database.txt? if not then thats not gonna work ;P
Posts 1–7 of 7 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Talk with us