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
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