9
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

4 Answers 4

11

You can use Attributes property of FileInfo class..

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

}
11

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

This is what you need:

bool isHidden = (File.GetAttributes(fileName) & FileAttributes.Hidden) == FileAttributes.Hidden;
0
3
file.Attributes.HasFlag(FileAttributes.Hidden)

Returns true/false

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.