I currently have the following code, that will count the number of directory paths that don’t exist:
int failedImports = 0;
if (this.fileExplorer.ShowDialog() == DialogResult.OK)
{
string importFile = this.fileExplorer.FileName;
string importedDirs = File.ReadAllText(importFile);
var result = Regex.Split(importedDirs, "\r\n|\r|\n");
foreach (string item in result)
{
if (!String.IsNullOrEmpty(item.ToString()) && Directory.Exists(item.ToString()))
{
this.lstbDirectories.Items.Add(item);
}
else
{
string desc;
failedImports++;
if (failedImports > 1) { desc = "Directories"; } else { desc = "Directory"; }
lblImportStatus.Text = (String.Format("{0} {1} failed to be\nimported. Please check that\nthey exist and try again.", failedImports, desc));
}
}
}
How would I go about writing each failed directory import into an array so I could display the failed entries to the user?
Thank you!
Create a
List<string>and callAdd()on each bad string.