It is populated from Access database using the following code:
chListBox.Items.Clear()
If conn.State = ConnectionState.Open Then conn.Close()
conn.Open()
Dim cmd As New OleDbCommand("select SubTitle from Phoneme_Analyser where MainTitle='" & cmbSubTitle.SelectedItem & "'", conn)
Dim dr As OleDbDataReader = cmd.ExecuteReader
While dr.Read()
chListBox.Items.Add(dr(0).ToString)
End While
dr.Close()
conn.Close()
I have .rtf files in a directory, I also save those files name in access database.
I want if I select or check any item in the CheckListBox and click on delete button, let it also delete the corresponding files in the directory.
I tried the following code but it did not work.
Dim directoryName As String = Application.StartupPath + "\Data\" & cmbMaintitle.SelectedItem & "\" & cmbSubTitle.Text & "\"
'get all files
Dim AllFiles As List(Of String) = Directory.GetFiles(directoryName, "*.*", SearchOption.TopDirectoryOnly).ToList()
'files which can NOT be deleted
Dim ExcludeFiles As List(Of String) = chListBox.Items.OfType(Of String).Selec(Function(x) directoryName + x).ToList()
'files to delete
Dim FilesToDelete = AllFiles.Except(ExcludeFiles)
For Each f As String In FilesToDelete
File.Delete(f)
Next