过滤坏的目录路径

本文关键字:路径 过滤 | 更新日期: 2023-09-27 18:08:09

我目前有以下代码,它将计算不存在的目录路径的数量:

    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));
            }
        }
    }

如何将每个失败的目录导入写入数组中,以便向用户显示失败的条目?

谢谢!

过滤坏的目录路径

创建一个List<string>,并在每个坏字符串上调用Add()