FileSystemInfo Class provides the base class for both FileInfo and DirectoryInfo objects.
using System;
using System.IO;
class Program
{
static void Main(string[] args)
{
foreach (string entry in Directory.GetDirectories(@"C:\"))
{
DisplayFileSystemInfoAttributes(new DirectoryInfo(entry));
}
}
static void DisplayFileSystemInfoAttributes(FileSystemInfo fsi)
{
string entryType = "File";
if ((fsi.Attributes & FileAttributes.Directory) == FileAttributes.Directory )
{
entryType = "Directory";
}
Console.WriteLine("{0} entry {1} was created on {2:D}", entryType, fsi.FullName, fsi.CreationTime);
}
}
Related examples in the same category