GooliveR
GooliveR

Reputation: 244

How to check whether a file is hidden?

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

I can not understand how to know that whether the file is hidden on the way

Upvotes: 9

Views: 7851

Answers (4)

Slai
Slai

Reputation: 22866

For a single file operation prefer the System.IO.File static methods ( and for multiple operations on the same 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;

Upvotes: 11

Daniel A. White
Daniel A. White

Reputation: 190907

This is what you need:

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

Upvotes: 6

rsqLVo
rsqLVo

Reputation: 508

file.Attributes.HasFlag(FileAttributes.Hidden)

Returns true/false

Upvotes: 3

L.B
L.B

Reputation: 116108

You can use Attributes property of FileInfo class..

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

}

Upvotes: 11

Related Questions