It is really difficult for me because I donβt know the correct term used for this, but essentially what I want to execute is .. If my code cannot execute it, it jumps and tried the following. Not sure if I need to use a try and catch loop, but here it goes.
As you can see, I am trying to delete material from the temp folder with the click of a button, and this leads me to my computer, saying that
Access to the path "file name" is denied.

I would like the code to skip this and go to the next file and try this one or even better just give the code access to delete the file, and not if the file is used, of course.
Is it 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(); } }
source share