This is really hard for me because I dont know the correct term used for this but essentially what I want to accomplish is.. If my code cant execute it jumps over and tried the next thing.. Not sure if I need to use a try & catch loop but here it goes.
As you can see I am trying to delete stuff from my temp folder with a press of a button and it throws me a error on my PC saying that
Access to the path "file name" is denied.
I would like the code to overlook that and jump to the next file and try that one or even better just give the code access to delete the file, not if the file is in use of course.
Is this possible?
private void label6_Click(object sender, EventArgs e)
{
string tempPath = Path.GetTempPath();
DirectoryInfo di = new DirectoryInfo(tempPath);
foreach (FileInfo file in di.GetFiles())
{
file.Delete();
}
}