Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 24 additions & 4 deletions Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,29 @@ static void Main(string[] args)

private static void SetReadOnly(string fileName, bool toBeReadOnly)
{
var attr = File.GetAttributes(fileName);
attr = toBeReadOnly ? attr | FileAttributes.ReadOnly : attr & ~FileAttributes.ReadOnly;
File.SetAttributes(fileName, attr);
try {
var attr = File.GetAttributes(fileName);
attr = toBeReadOnly ? attr | FileAttributes.ReadOnly : attr & ~FileAttributes.ReadOnly;
File.SetAttributes(fileName, attr);
}
catch(Exception ex)
{
if (ex is ArgumentException ||
ex is PathTooLongException ||
ex is PathTooLongException ||
ex is DirectoryNotFoundException ||
ex isFileNotFoundException)
{
//Something is wrong with the file...
throw ex;
}
if (ex is NotSupportedException ||
ex is UnauthorizedAccessException)
{
//You have a security or implementation problem
throw ex;
}
}
}


Expand Down Expand Up @@ -122,4 +142,4 @@ private static string ProcessLinePart(string line, string part) {
return line;
}
}
}
}