How to check if a file is hidden?

File.SetAttributes((new FileInfo((new Uri(Assembly.GetExecutingAssembly().CodeBase)).LocalPath)).Name, FileAttributes.Hidden);
if(Check file Hidden )
....
else
()

I do not understand how to find out if a file is hidden in the path

+4
source share
4 answers

You can use the Attributesclass property FileInfo ..

var fInfo = new FileInfo(..);
if (fInfo.Attributes.HasFlag(FileAttributes.Hidden))
{

}
+6
source

This is what you need:

bool isHidden = (File.GetAttributes(fileName) & FileAttributes.Hidden) == FileAttributes.Hidden;
+3
source

For single-file operations, prefer static methods System.IO.File(and for multiple operations in a single file System.IO.FileInfo):

bool isHidden1 = File.GetAttributes(path).HasFlag(FileAttributes.Hidden);

//bool isHidden2 = (File.GetAttributes(path) & FileAttributes.Hidden) > 0; 
//bool isHidden3 = ((int)File.GetAttributes(path) & 2) > 0;
+2
source
file.Attributes.HasFlag(FileAttributes.Hidden)

Returns true/false

0
source

Source: https://habr.com/ru/post/1655002/


All Articles