How to do to not consider the system folder?

there is a code you need to get all the text files on all drives ,my code considers system folders and climbs error
try
{
 string[] allFoundFiles=null;
 foreach (var item in Drives)
{
 allFoundFiles = Directory.GetFiles(item, "*.txt", SearchOption.AllDirectories);


 foreach (string file in allFoundFiles)
{
 row = table.NewRow();
 str = file.Split('\\');

 row["Name"] = str[1];
 row["Path"] = str[0];

table.Rows.Add(row);

}
 }

as these folders around
March 19th 20 at 09:22
1 answer
March 19th 20 at 09:24
Solution
If anyone is interested here is the solution
public IEnumerable<string> SafeEnumerateFiles(string path, string searchPattern, SearchOption searchOption)
{

 Stack<string> dirs = new Stack<string>();
dirs.Push(path);

 while (dirs.Count > 0)
{
 string currentDirPath = dirs.Pop();
 if (searchOption == SearchOption.AllDirectories)
{
try
{
 string[] subDirs = Directory.GetDirectories(currentDirPath);
 foreach (string subDirPath in subDirs)
{

 if ((File.GetAttributes(subDirPath) & (FileAttributes.Hidden | FileAttributes.System)) != (FileAttributes.Hidden | FileAttributes.System))
{
dirs.Push(subDirPath);
}
}
}
 catch (UnauthorizedAccessException)
{
continue;
}
 catch (DirectoryNotFoundException)
{
continue;
}
}

 string[] files = null;
try
{
 files = Directory.GetFiles(currentDirPath, searchPattern);
}
 catch (UnauthorizedAccessException)
{
continue;
}
 catch (DirectoryNotFoundException)
{
continue;
}

 foreach (string filePath in files)
{
 yield return filePath;
}
}
 }

Find more questions by tags C#