Loading ...

Working with File Attributes | CodeAsp.Net

Working with File Attributes

 /5
0 (0votes)

Introduction

Here I’m going to show in this small blog how one can manipulate attribute(s) of a file.

Sample path

Getting file’s attribute(s)

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.

Getting file’s attribute(s)

Setting file’s attribute(s)

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.

Setting file’s attribute(s)

Clearing file’s attribute(s)

It can be done by simply invoking SetAttributes static method by passing FileAttributes.Normal enum as a parameter.

Clearing file’s attribute(s)

Getting a specific attribute

To check whether a file has a particular attribute or not, simply use bitwise AND (&) operator with a mask of specific attributes.

Getting a specific attribute

Adding a attribute(s) in a current file

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.

Adding a attribute(s) in a current file

Deleting a attribute(s) from a current file

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).

Deleting a attribute(s) from a current file

Conclusion

Hope all of you will like this blog.

Comments (no comments yet)

Top Posts