Get Directory attribute list as a string and file count under it in CSharp

Description

The following code shows how to get Directory attribute list as a string and file count under it.

Example


   /*ww  w  . j  a v  a  2  s.  c  o  m*/

using System;
using System.IO;

class MainClass
{
    public static void Main(string[] args)
    {
        FileInfo file = new FileInfo("c:\\test.txt");

        // Display directory information.
        DirectoryInfo dir = file.Directory;

        if (dir.Exists)
        {
            Console.WriteLine(dir.Attributes.ToString());
            Console.WriteLine("Directory contains: " + dir.GetFiles().Length.ToString() + " files");
        }

    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    IO »




File Attribute
File Security
Directory Attribute
Directory Recursive
Binary File
Text Field
Buffered IO
Create Copy Delete Move
CSV
Drive
File System Watcher
Isolated Storage
MemoryStream
Serialize
Zip