C# Program to Check the Information of the File
Last Updated :
01 Nov, 2021
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#
using System;
using System.IO;
class GFG{
static void Main()
{
FileInfo information = new FileInfo( "C:\\sravan\\data.txt" );
FileAttributes attributes = information.Attributes;
Console.WriteLine( "Attribute of the File is {0}" , attributes);
}
}
|
Output:
Attribute of the File is Archive
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...