Covers topics on the Microsoft Certification Exam for the .NET Framework (Exam 70-536, Microsoft .NET Framework - Application Development Foundation)

Tuesday, March 18, 2008

FileSystemInfo Properties

The FileSystemInfo Class is the base class for the FileInfo and DirectoryInfo classes. The best way to understand a particular class in the .NET Framework (and any language for that matter) is to write some code to use it.

Here is a snippet that uses many of the properties available in the FileSystemInfo class.

FileSystemInfo exampleFile = new FileInfo(@"C:\WINDOWS\System32\command.com");

Console.WriteLine("\n-------------------------------------\n");

//Please keep these two lines if you would like to use this code on your site
Console.WriteLine("FileInfo Example");
Console.WriteLine("Created by Charles Cozad, http://www.mctscertification.blogspot.com");

Console.WriteLine("\n-------------------------------------\n");

if (exampleFile.Exists)
{
Console.WriteLine("File Name: {0}", exampleFile.Name);
Console.WriteLine("File Extension: {0}", exampleFile.Extension);
Console.WriteLine("Full File Name: {0}", exampleFile.FullName);
Console.WriteLine("Creation Time: {0}", exampleFile.CreationTime);
Console.WriteLine("Last Access Time: {0}", exampleFile.LastAccessTime);
Console.WriteLine("Last Write Time: {0}", exampleFile.LastWriteTime);
Console.WriteLine("File Attributes: {0}", exampleFile.Attributes);
}
else
{
Console.WriteLine("File does not exist");
}

Additional Resources
FileSystemInfo Class (Microsoft)

No comments:

Support This Site

LinkShare  Referral  Prg