When I run the program and input "1 20", my program will delete 0 1 2 20. What I want it to do was just to delete 1 and 20 only.
The portion of my program that I'm having issues with:
Console.WriteLine("Do you want to delete file? (Y/N)");
string answer = Console.ReadLine();
string dir = @"C:\Users\1\Downloads\Project Resources Files\";
string[] textFiles1 = Directory.GetFiles(dir, "*", SearchOption.AllDirectories);
int counter = 0;
if (answer == "y" || answer == "Y")
{
Console.WriteLine("Select file to delete. To delete file, type file No<space>file No. Example: 1 3");
string keyin = Console.ReadLine();
Console.WriteLine("Do you really want to delete? (y/n)");
string cfm = Console.ReadLine();
if(cfm == "Y" || cfm == "y")
foreach (var file in textFiles1)
{
if (keyin.Contains(counter.ToString()))
{
File.Delete(file);
Console.WriteLine("\n File number " + counter + " deleted sucessfully");
}
counter++;
}
if(cfm == "n" || cfm == "N")
{
goto back;
}