2011-09-07 8 views
1

을 필터링 나는 현재 다음과 같은 코드를 가지고, 디렉토리 경로의 수를 세는 것 즉 존재하지 않는 :나쁜 디렉토리 경로

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

가 어떻게 각각의 작성에 대한 갈 것이라고 그렇게 배열로 디렉터리 가져 오기 실패 실패한 항목을 사용자에게 표시 할 수 있습니까?

감사합니다.

답변

3

List<string>을 만들고 각 잘못된 문자열에 Add()을 호출하십시오.

+0

목록을 포함하도록 내 코드가 변경되었습니다 (생각하지 않았습니다). 도움을 주셔서 감사합니다. – MrDKOz

관련 문제