Deleting file, but is access denied Deleting file, but is access denied windows windows

Deleting file, but is access denied


I also had the problem, hence me stumbling on this post. I added the following line of code before and after a Copy / Delete.

Delete

File.SetAttributes(file, FileAttributes.Normal);File.Delete(file);

Copy

File.Copy(file, dest, true);File.SetAttributes(dest, FileAttributes.Normal);


Building upon the answer - For me I had to set the folder and the files inside it to normal attributes.

    DirectoryInfo directory = new DirectoryInfo("/path/to/file");    directory.Attributes = FileAttributes.Normal;    foreach (FileInfo file in directory.GetFiles()) {        file.Attributes = FileAttributes.Normal;    }