Sai Parthiv

Sai Parthiv

  • NA
  • 11
  • 725

How to exclude an array from search in C#

May 16 2017 4:04 AM
I've an array. Let's say;
  1. private string[] WhiteList =  
  2. {  
  3. "abcxyz.cs",  
  4. "mouseapi.dll",  
  5. "SensitivtyFix.asi",  
  6. "drake.mp3"  
  7. };  
Another array,
  1. private string[] SuspectedFiles =  
  2. {  
  3. ".cs",  
  4. "d3d9.dll",  
  5. "sqlite3.dll",  
  6. "mod_sa.ini",  
  7. "mod_sa.raw",  
  8. ".cleo",  
  9. ".asi"  
  10. };  
Now I want to exclude WhiteList array from a directory/file search. How do I achieve that?
For this search, I'm using another array called SuspectedFiles as mentioned above from which I could fetch desired files but I'm unable to exclude files from the array Whitelist.
This is my code;
 
 I could get results of files from SuspectedFiles array but couldn't remove files contained in Whitelist array from the search results.
  1. private void VerifySuspectedFiles()  
  2.         {  
  3.             listBox1.Enabled = true;  
  4.   
  5.             DirectoryInfo DirInf = new DirectoryInfo(GetGtaRegistryPath());  
  6.             int GetSize = SuspectedFiles.GetLength(0);  
  7.   
  8.             if (!DirInf.Exists)  
  9.             {  
  10.                 MessageBox.Show("This directory does not exist!""Error", MessageBoxButtons.OK, MessageBoxIcon.Error);  
  11.   
  12.                 return;  
  13.             }  
  14.   
  15.             if (GetSize == 0)  
  16.             {  
  17.                 return;  
  18.             }  
  19.   
  20.             for (int i = 0; i < GetSize; ++i)  
  21.             {  
  22.                 foreach (var File in DirInf.GetFiles("*", SearchOption.AllDirectories))  
  23.                 {  
  24.                     if (File.FullName.Contains(SuspectedFiles[i]) && !File.FullName.Contains(WhiteList[i]))  
  25.   
  26.                     {  
  27.                         listBox1.Items.Add("File: " + File.FullName);  
  28.                     }  
  29.                 }  
  30.             }  
  31.         }  
 
Any help would be great. Thank You.

Answers (1)