Check if a File is hidden in C#

CsharpProgrammingServer Side Programming

To retrieve the attributes of a file, use the FileAttributes Eumeration. It has various members like compressed, directory, hidden, etc.

To check if a file is hidden, use the hidden member name.

If the FileAttributes.hidden is set that would mean the file is hidden. Firstly, get the path to find the attributes.

FileAttributes attributes = File.GetAttributes(path);

If the following is set, that would mean the file is now hidden using the hidden member name.

 File.SetAttributes(path, File.GetAttributes(path) | FileAttributes.Hidden);
Console.WriteLine("The {0} file is hidden.", path);
raja
Published on 17-Sep-2018 12:52:34
Advertisements