4
Reply

Looping through an array

Steve DeYoung

Steve DeYoung

Jul 14 2017 12:31 AM
246
I am trying to loop through an array. The array is filled with names from a text file. If the name isn't in the array I want to skip it and continue looping. This is what I have so far.. The problem i'm having is when the name doesn't exist the loop ends and falls into the catch.  
 
try
{
string[] file = File.ReadAllLines(@"C:\Users\Steve\Documents\Visual Studio 2015\Projects\FileCopier\FileCopier\File.txt");
foreach(string folder in file)
{
if (file.Contains(folder))
{
Directory.Move(Path.Combine(sourceDirectory, folder), Path.Combine(destinationDirectory, folder));
}
else
{
}
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
 

Upload Source Code  Select only zip and rar file.
Answers (4)