codice:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
report = "\Report.txt"
Timer1.Enabled = True
testfile = TextBox2.Text & report
path = TextBox1.Text
Try
Using sw As StreamWriter = New StreamWriter(testfile)
sw.WriteLine("INIZIO ELENCO FILE TROVATI")
sw.WriteLine("-------------------------------------------------------------------------")
sw.WriteLine("CARTELLA MADRE: [" & path & "] " & "RICERCA FILE ---> " & ComboBox2.Text)
sw.WriteLine("-------------------------------------------------------------------------")
sw.WriteLine("INIZIO RICERCA ----> " & TimeOfDay)
sw.WriteLine("-------------------------------------------------------------------------")
For Each foundfile As String In My.Computer.FileSystem.GetFiles(path)
If ComboBox2.Text = "Senza estensione" Then
punto = "."
If InStr(foundfile, punto) <= 0 Then
ListBox1.Items.Add(foundfile)
sw.WriteLine(foundfile)
i = i + 1
End If
Else
If InStr(UCase(foundfile), UCase(ComboBox2.Text)) > 0 Then
ListBox1.Items.Add(foundfile)
sw.WriteLine(foundfile)
i = i + 1
End If
End If
Next
For Each founddirectory As String In My.Computer.FileSystem.GetDirectories(path, FileIO.SearchOption.SearchAllSubDirectories)
ListBox2.Items.Add(founddirectory)
For Each foundfile As String In My.Computer.FileSystem.GetFiles(founddirectory)
If ComboBox2.Text = "Senza estensione" Then
punto = "."
If InStr(foundfile, punto) <= 0 Then
ListBox1.Items.Add(foundfile)
sw.WriteLine(foundfile)
i = i + 1
End If
Else
If InStr(UCase(foundfile), UCase(ComboBox2.Text)) > 0 Then
ListBox1.Items.Add(foundfile)
sw.WriteLine(foundfile)
i = i + 1
End If
End If
Next
Next
sw.WriteLine("-------------------------------------------------------------------------")
sw.WriteLine("RICERCA FILES TERMINATA")
sw.WriteLine("-------------------------------------------------------------------------")
sw.WriteLine("SONO STATI TROVATI " & i & " FILES " & ComboBox2.Text)
sw.WriteLine("-------------------------------------------------------------------------")
sw.WriteLine("FINE RICERCA ----> " & TimeOfDay)
sw.Close()
End Using
If CheckBox1.Checked = True Then
Dim percalleg As String
Dim dest As String
dest = TextBox3.Text
percalleg = testfile
Dim Msg As New System.Net.Mail.MailMessage("carlofanuli@rivacold.com", dest, "Log ricerca file", "Questo è un messaggio di prova")
Dim Smtp As New System.Net.Mail.SmtpClient("mailserver")
Msg.Attachments.Add(New System.Net.Mail.Attachment(percalleg))
Smtp.Send(Msg)
End If
CheckBox1.Enabled = False
Button1.Enabled = False
Catch ex As Exception
MsgBox("Errore")
End Try
End Sub