Set File and Directory Attributes - CSharp File IO

CSharp examples for File IO:File

Description

Set File and Directory Attributes

Demo Code


using System;//from  www.  j av  a2  s.  co m
using System.IO;

    static class Recipe05_02
    {
        static void Main()
        {
            FileInfo file = new FileInfo(@"C:\Windows\win.ini");
            Console.WriteLine(file.Attributes.ToString());

            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).");
            }
        }
    }

Result


Related Tutorials