C # issues: File.Delete () in .exe
I am working on a program that should delete multiple .zip files. It works as intended, when I start from Visual Studio, the problem is when I compiled it in .exe format. For anything more than 2 zip files, the executable will stop and exit the third file, and also the .exe will disappear from the bin \ debug directory from which I ran it.
Here's a short program describing what I am trying to do, gives the same results on my machine.
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DeleteMultipleFilesFromDirectory
{
class Program
{
static void Main(string[] args)
{
string dir = "C:\\ZipDirectory\\DeleteZipFiles\\";
Directory.GetFiles(dir,"*.zip").ToList().ForEach(s => File.Delete(s));
}
}
}
+3
source to share