FileInfo.Attributes : FileInfo « System.IO « C# / C Sharp by API






FileInfo.Attributes

 
using System;
using System.IO;

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

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

   
  








Related examples in the same category

1.new FileInfo(String fileName)
2.FileInfo.Create()
3.FileInfo.CreationTime
4.FileInfo.CopyTo(String fileName)
5.FileInfo.Delete
6.FileInfo.Directory
7.FileInfo.FullName
8.FileInfo.LastAccessTime
9.FileInfo.MoveTo(String path)
10.FileInfo.Open
11.FileInfo.OpenRead
12.FileInfo.OpenText
13.FileInfo.OpenWrite()