Check if a File is hidden in C#


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

Updated on: 30-Jul-2019

516 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements