You need to check the existence of the file by the paths from List dino, if there are nonexistent files, then delete these paths and transfer this new data to the dino sheet or to the new sheet again so that you can use these paths later in the cycles.
static void Main(string[] args) { string[] basePaths = { "folders\\text.txt", "folders\\text.txt", "folders\\text.txt" }; List<string> dino = new List<string>(basePaths); I try to do all this through a cycle, but in the cycle you cannot change the collection data
foreach (string dino2 in dino) { if (!(File.Exists(dino2))) dino.Remove(dino2); } I looked through many examples in the documentation and on the Internet, found nothing similar, maybe I just didn’t stumble upon the right UPD option: I tried the for loop, the program stops
List<string> dino = new List<string>(basePaths); for (int i = dino.Count - 1; i >= 0; i--) { if (!(File.Exists(dino[i]))) { dino.Remove(dino[i]); } Console.WriteLine(dino[i]); }