FileAttributes.ReadOnly : File Attribute : File Directory Stream C# Examples


C# Examples » File Directory Stream » File Attribute »

 

FileAttributes.ReadOnly









    
using  System;
using  System.IO;

static  class  MainClass
{
        static  void  Main()
        {
                FileInfo  file  =  new  FileInfo("data.txt");

                Console.WriteLine(file.Attributes.ToString());

                //  This  test  fails,  because  other  attributes  are  set.
                if  (file.Attributes  ==  FileAttributes.ReadOnly)
                {
                        Console.WriteLine("File  is  read-only  (faulty  test).");
                }

                if  ((file.Attributes  &  FileAttributes.ReadOnly)  ==  FileAttributes.ReadOnly)
                {
                        Console.WriteLine("File  is  read-only  (correct  test).");
                }
        }
}
    
   
  
   



Output

Archive, NotContentIndexed


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo File Directory Stream
» File Attribute