Files and Directories share certain properties that we can
use to determine the created date of a file or directory, size, last modified
date, attributes, the extension of file, etc. These properties can be viewed
by opening the file’s Properties dialog. We can open this dialog from windows
explorer by either right clicking on the file and selecting Properties from the
context menu or selecting Properties from file menu. Using both FileInfo and
DirectoryInfo classes we can access the properties and modify them. In Listing
1 the properties of a file have been accessed programmatically.
Listing 1
private void show()
{
FileInfo file = new FileInfo("C:/Documents and Settings/SanjitSil/Test.txt");
Response.Write("Location :" + file.FullName + "<BR>" + "Size :" + file.Length
+ "<BR>" + "Created :" + file.CreationTime + "<BR>" +
"Modified : file.LastWriteTime + "<BR>" + "Accessed :
" + file.LastAccessTime + "<BR>" + "Attributes :" + file.Attributes + "<BR>
" + "Extension :" + file.Extension + "<BR>");
}
In the above specified code a text file has been taken. Each
time we edit the file, the value of the properties of the file will be getting
changed. For more information on File, Directory, FileInfo and DirectoryInfo
classes, readers may read my earlier article entitled “Working
with Files and Directories.”