November 2, 2010

Deleting a Read-Only File

See also the FileAttributesExtender class
and the PathCombine class
string fullPath = PathCombine(pathRoot, relativePath);
if (File.Exists(fullPath))
{
    FileAttributes fas = File.GetAttributes(fullPath);
    if (fas.Contains(FileAttributes.ReadOnly))
        File.SetAttributes(fullPath, FileAttributes.Normal);
    File.Delete(fullPath);
}

No comments: