I\'ve got a junk directory where I toss downloads, one-off projects, email drafts, and other various things that might be useful for a few days but don\'t need to be saved f
According to File.Delete's documentation,, you'll have to strip the read-only attribute. You can set the file's attributes using File.SetAttributes().
using System.IO;
File.SetAttributes(filePath, FileAttributes.Normal);
File.Delete(filePath);
The equivalent if you happen to be working with a FileInfo object is:
file.IsReadOnly = false;
file.Delete();
Why do you need to check? Just forcibly clear the read-only flag and delete the file.
Hm, I think I'd rather put
>del /F *
into a sheduled task. Maybe wrapped by a batch file for logging statistics.
Am I missing something?
According to File.Delete's documentation,, you'll have to strip the read-only attribute. You can set the file's attributes using File.SetAttributes().