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:
Post a Comment