Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 筛选出错误的目录路径_C#_Arrays_Filtering - Fatal编程技术网

C# 筛选出错误的目录路径

C# 筛选出错误的目录路径,c#,arrays,filtering,C#,Arrays,Filtering,我目前有以下代码,将计算不存在的目录路径数: int failedImports = 0; if (this.fileExplorer.ShowDialog() == DialogResult.OK) { string importFile = this.fileExplorer.FileName; string importedDirs = File.ReadAllText(importFile); var result

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

    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));
            }
        }
    }
如何将每个失败的目录导入写入一个数组,以便向用户显示失败的条目


谢谢大家!

创建一个
列表
并对每个错误字符串调用
Add()

将我的代码更改为包含列表(没有想到这一点)非常感谢您的帮助!