How can I restrict only .cor files to be added to the list. The code bellow allows .corx, .corxx, .corxxx to be added to the list. I only want .cor files. Is that possible?
private void btn_models_Click(object sender, EventArgs e)
{
DialogResult res = dlg_find_folder.ShowDialog();
if (res == DialogResult.OK)
{
tbx_models.Text = dlg_find_folder.SelectedPath;
populateChecklist(tbx_models.Text, "cor");
cbx_all.CheckState = System.Windows.Forms.CheckState.Checked;
}
}
/// <summary>
/// Function populates the models checklist based on the models found in the specified folder.
/// </summary>
/// <param name="directory">Directory in which to search for files</param>
/// <param name="extension">File extension given without period</param>
private void populateChecklist(String directory, String extension)
{
clb_run_list.Items.Clear();
System.Collections.IEnumerator enumerator;
String mdl_name;
try
{
enumerator = System.IO.Directory.GetFiles(directory, "*." + extension).GetEnumerator();
while (enumerator.MoveNext())
{
mdl_name = parse_file_name((String)enumerator.Current, directory, extension);
clb_run_list.Items.Add(mdl_name);
}
}
catch
{
//above code will fail if the initially specified directory does not exist
//MessageBox.Show("The specified directory does not exist. Please select a valid directory.");
}
return;
}