Given a file, now our task is to view the information of this file through C#. So to do this task we use FileInfo class. This class provides different types of properties and methods for creating, copying, deleting, opening, and moving files. It is also, used for creating FileStream objects. So here we create an object of the FileInfo class which contains the file name.
Syntax:
FileInfo info = new FileInfo("C:\\sravan\\data.txt");
Example:
In this example, we consider a file named ” data.txt” present in the “sravan” folder in the C drive or “C:\\sravan\\data.txt”. Now with the help of this path, we will find the information of “data.txt” file using the Attributes property. This property returns an enumerated constant which is encoded as enum flag.
// C# program to display the information of file using System;
using System.IO;
class GFG{
static void Main()
{ // Get the file
FileInfo information = new FileInfo( "C:\\sravan\\data.txt" );
// Get the file information
FileAttributes attributes = information.Attributes;
// Display file information
Console.WriteLine( "Attribute of the File is {0}" , attributes);
} } |
Output:
Attribute of the File is Archive