Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check whether a file is hidden?

Tags:

c#

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

like image 229
GooliveR Avatar asked Sep 18 '16 19:09

GooliveR


People also ask

How do you check if a file is hidden?

isHidden() method of File class in Java can use be used to check if a file is hidden or not. This method returns a boolean value – true or false. Parameters: Path to the file to test.

What files are hidden?

A hidden file is a file which has the hidden attribute turned on so that it is not visible to users when exploring or listing files. Hidden files are used for storage of user preferences or for preservation of the state of utilities. They are created frequently by various system or application utilities.

How can I see the hidden files in Windows 7?

Windows 7. Select the Start button, then select Control Panel > Appearance and Personalization. Select Folder Options, then select the View tab. Under Advanced settings, select Show hidden files, folders, and drives, and then select OK.


2 Answers

You can use Attributes property of FileInfo class..

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

}
like image 128
L.B Avatar answered Sep 22 '22 06:09

L.B


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;
like image 44
Slai Avatar answered Sep 19 '22 06:09

Slai