allora credo che così sia corretto, corregetemi se sbaglio
, però dovrei inserire un messagebox cge mi avvisi quando la ricerca è conclusa:
codice:
Private Function SearchFile(ByVal Dir As String, ByVal nomeFile As String) As String
On Error Resume Next
Dim Directories As String()
Dim iDirectory As String, filePath As String
Dim risposta As MsgBoxResult
SearchFile = String.Empty
Directories = IO.Directory.GetDirectories(Dir)
For Each iDirectory In Directories
Application.DoEvents()
filePath = SearchFile(iDirectory, nomeFile)
If IO.File.Exists(IO.Path.Combine(Dir, nomeFile)) Then
Application.DoEvents()
ListBox1.Items.Add(Dir)
risposta = MsgBox("Il percorso è corretto? " + (Dir + "\" + nomeFile), MsgBoxStyle.YesNo, "Controllo path del file....")
If risposta = MsgBoxResult.Yes Then
Return Dir
MsgBox("Ricerca terminata", ControlChars.CrLf & MsgBoxStyle.Information, "Fine")
Exit Function
Else
End If
End If
Next
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
ListBox1.Items.Clear()
Dim nomefile As String = TextBox1.Text
Dim strDrives() As String = IO.Directory.GetLogicalDrives()
Dim Directories As String()
Dim iDirectory, filePath As String
Dim driveDetails As IO.DriveInfo
For Each drive As String In strDrives
Application.DoEvents()
driveDetails = New IO.DriveInfo(drive)
If driveDetails.DriveType.ToString = "Fixed" Then
Directories = IO.Directory.GetDirectories(drive)
For Each iDirectory In Directories
Application.DoEvents()
filePath = SearchFile(iDirectory, nomefile)
Next
End If
Next
End Sub