Below is code to adjust file attributes.
Can someone annotate this code
I've read it over a few times and I still can't figure out why the underlined isn't redundant...
Code:
[COLOR=blue]Public[/COLOR] [COLOR=blue]Shared[/COLOR] [COLOR=blue]Sub[/COLOR] Main()
[COLOR=blue]Dim[/COLOR] path [COLOR=blue]As[/COLOR] [COLOR=blue]String[/COLOR] = [COLOR=#a31515]"c:\temp\MyTest.txt"[/COLOR]
[COLOR=green]' Create the file if it exists. [/COLOR]
[COLOR=blue]If[/COLOR] File.Exists(path) = [COLOR=blue]False[/COLOR] [COLOR=blue]Then[/COLOR]
File.Create(path)
[COLOR=blue]End[/COLOR] [COLOR=blue]If[/COLOR]
[COLOR=blue]Dim[/COLOR] attributes [COLOR=blue]As[/COLOR] FileAttributes
attributes = File.GetAttributes(path)
[U][COLOR=blue]If[/COLOR] (attributes [COLOR=blue]And[/COLOR] FileAttributes.Hidden) = FileAttributes.Hidden [COLOR=blue]Then[/COLOR][/U] [U]' FA.Hidden = FA.Hidden...? Is this necessary?[/U]
[COLOR=green]' Show the file.[/COLOR]
attributes = RemoveAttribute(attributes, FileAttributes.Hidden)
File.SetAttributes(path, attributes)
Console.WriteLine([COLOR=#a31515]"The {0} file is no longer hidden."[/COLOR], path)
[COLOR=blue]Else[/COLOR]
[COLOR=green]' Hide the file.[/COLOR]
File.SetAttributes(path, [U]File.GetAttributes(path) [COLOR=blue]Or[/COLOR] FileAttributes.Hidden[/U]) [U]'...how is this setting both existing attributes and a new hidden attribute?[/U]
Console.WriteLine([COLOR=#a31515]"The {0} file is now hidden."[/COLOR], path)
[COLOR=blue]End[/COLOR] [COLOR=blue]If[/COLOR]
[COLOR=blue]End[/COLOR] [COLOR=blue]Sub[/COLOR]
[COLOR=blue]Public[/COLOR] [COLOR=blue]Shared[/COLOR] [COLOR=blue]Function[/COLOR] RemoveAttribute([COLOR=blue]ByVal[/COLOR] attributes [COLOR=blue]As[/COLOR] FileAttributes, [COLOR=blue]ByVal[/COLOR] attributesToRemove [COLOR=blue]As[/COLOR] FileAttributes) [COLOR=blue]As[/COLOR] FileAttributes
[COLOR=blue]Return[/COLOR] attributes [COLOR=blue]And[/COLOR] ([COLOR=blue]Not[/COLOR] attributesToRemove) ' [U]??? what is this returning?[/U]
[COLOR=blue]End[/COLOR] [COLOR=blue]Function[/COLOR]
Can someone annotate this code
