Home » .Net » C# file handling programs

C# program to get attributes of a specified file

In this C# program, we are going to learn how to get attributes of a file? Here, method File.GetAttributes() is using.
Submitted by IncludeHelp, on October 29, 2017

Given a file, and we have to get and print file’s attribute using C# program.

File.GetAttributes()

This is a method of "File" class, which returns the specified file's attributes.

Syntax:

FileAttributes GetAttributes(path);

Parameter(s):

  1. path - Filename with its location.

Return value:

This method returns object of FileAttributes, File attribute can be following:

  • Archive
  • Compressed
  • Device
  • Hidden
  • ReadOnly, etc

Program

using System;
using System.IO;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main()
        {
            FileAttributes F = File.GetAttributes("B123.TXT");

            Console.WriteLine("Attributes are :"+F.ToString());
       
        }
    }
}

Output

Attributes are :Hidden, Archive

Note: In above program, we need to remember, when we use "File" class, System.IO namespace must be included in the program.





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.



Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.