Here I’m going to show in this small blog how one can manipulate attribute(s) of a file.
Attributes of a file can be getting by using GetAttributes static method of File class. This method returns FileAttributes enum which is a bitwise combination of file attribute flags.
Attributes of a file can be set by using SetAttributes static method of File class. This method takes bitwise combination of FileAttributes enumeration as parameters.
It can be done by simply invoking SetAttributes static method by passing FileAttributes.Normal enum as a parameter.
To check whether a file has a particular attribute or not, simply use bitwise AND (&) operator with a mask of specific attributes.
To add attribute(s) to the current file, simply get the current file attribute(s) first and then use bitwise OR (|) with the desired attributes.
To remove attribute(s) from the current file, simply get the current file attribute(s) first and then use bitwise AND (&) with a bitwise complement (~) of desired attribute(s).
Hope all of you will like this blog.