C# Program to get information about a file


To get information about a file means to get what all attributes are set for that particular file. For example, a file can be normal, hidden, archived, etc.

Firstly, use the FileInfo class −

FileInfo info = new FileInfo("hello.txt");

Now, use FileAttributes to get information about a file −

FileAttributes attr = info.Attributes;

The following is the code −

Example

 Live Demo

using System.IO;
using System;
public class Program {
   public static void Main() {
      using (StreamWriter sw = new StreamWriter("hello.txt")) {
         sw.WriteLine("This is demo text!");
      }
      FileInfo info = new FileInfo("hello.txt");
      FileAttributes attr = info.Attributes;
      Console.WriteLine(attr);
   }
}

Output

Normal

Samual Sam
Samual Sam

Learning faster. Every day.

Updated on: 22-Jun-2020

114 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements