Q:

C# program to get attributes of a specified file

0

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
  •  

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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.

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C# file handling (File class) solved programs/examples

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
C# program to set new file creation time... >>
<< C# program to set attributes of specified file...