File System Information |
|
The Date and Time a File Was Created |
After a file has been created, the operating system makes a note of the date and the time the file was created. This information can be valuable in other operations such as search routines. You too are allowed to change this date and time values to those you prefer. As mentioned already, the OS makes sure to keep track of the date and time a file was created. To find out what those date and time values are, you can access the get accessor of the FileSystemInfo.CreationTime property, which is of type DateTime. Here is an example of using it: |
Private Sub btnCreationDate_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) _ Handles btnCreationDate.Click Dim Filename As String Dim FileCreationTime As DateTime Dim StudentInformation As FileInfo Filename = "Student1.std" StudentInformation = My.Computer.FileSystem.GetFileInfo(Filename) If StudentInformation.Exists = True Then FileCreationTime = StudentInformation.CreationTime MsgBox(FormatDateTime(FileCreationTime, DateFormat.LongDate)) Else MsgBox("Unknown file") End If End Sub Of course, by formatting the value, you can get only either the date or only the time. If you don't like the date, the time, or both, that the OS would have set when the file was created, you can change them. To change one or both of these values, you can assign a desired DateTime object to the set accessor of the FileSystemInfo.CreationTime property.
Many applications allow a user to open an existing file and to modify it. When people work in a team or when a particular file is regularly opened, at one particular time, you may want to know the date and time that the file was last accessed. To get this information, you can access the FileSystemInfo.LastAccessTime property, which is of type DateTime. If you are interested to know the last date and time a file was modified, you can get the value of its FileSystemInfo.LastWriteTime property, which is of type DateTime.
The operating system requires that each file have a name. In fact, the name must be specified when creating a file. This allows the OS to catalogue the computer files. This also allows you to locate or identify a particular file you need. When reviewing or opening a file, to get its name, the FileInfo class is equipped with the Name property. Here is an example: MsgBox("The name of this file is: \"+ & fleLoan.Name & "\"") This string simply identifies a file.
With the advent of Windows 95 and later, the user doesn't have to specify the extension of a file when creating it. Because of the type of confusion that this can lead to, most applications assist the user with this detail. Some applications allow the user to choose among various extensions. For example, using Notepad, a user can open a text, a PHP, a script, or an HTML file. When you access a file or when the user opens one, to know the extension of the file, you can access the value of the FileSystemInfo.Extension property. Here is an example: MsgBox("File Extension: " & fleLoan.Extension)
One of the routine operations the operating system performs consists of calculating the size of files it holds. This information is provided in terms of bits, kilobits, or kilobytes. To get the size of a file, the FileInfo class is quipped with the Length property. Here is an example of accessing it: MsgBox("File Size: " & fleLoan.Length.ToString())
Besides its name, a file must be located somewhere. The location of a file is referred to as its path or directory. The FileInfo class represents this path as the DirectoryName property. Therefore, if a file has already been created, to get its path, you can access the value of the FileInfo.DirectoryName property. Besides the FileInfo.Directoryname, to know the full path to a file, you can access its FileSystemInfo.FullName property.
Attributes are characteristics that apply to a file, defining what can be done or must be disallowed on it. The Attributes are primarily defined by, and in, the operating system, mostly when a file is created. When the user accesses or opens a file, to get its attributes, you can access the value of its FileSystemInfo.Attributes property. This property produces a FileAttributes object. When you create or access a file, you can specify or change some of the attributes. To do this, you can create a FileAttributes object and assign it to the FileSystemInfo.Attributes property. FileAttributes is an enumeration with the following members: Archive, Compressed, Device, Directory, Encrypted, Hidden, Normal, NotContentIndexed, Offline, ReadOnly, ReparsePoint, SparseFile, System, and Temporary. |
|
||
Home | Copyright © 2008-2016, FunctionX, Inc. | |
|