File Information: Characteristics of a File |
|
Private Sub btnDateTimeCreated_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _ Handles btnDateTimeCreated.Click Dim fleMembers As FileInfo = New FileInfo("Persons.txt") Dim dteCreationTime As DateTime = fleMembers.CreationTime MsgBox("Date and Time Created: " + dteCreationTime.ToString()) End Sub
|
Practical Learning: Identifying a File |
|
The Extension of 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 confusions that this can lead to, most applications assist the user with this detail. For example, when we implemented the routines that allow the user to save or open a file, we specified a default extension for the Save Dialog or the Open Dialog objects. This allows the user not to care for the extension. Based on this, 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); |
The Size of a File |
One of the routine operations the operating system performs consists of calculation 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());
|
The Path to a File |
Besides the name of the file, it 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. |
Practical Learning: Finding the Path to a File |
|
The Attributes of a File |
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 accessed or open a file, to get its attributes, you can access the value of its FileSystemInfo.get_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 a FileAttributes object and assign it to the FileSystemInfo.set_Attributes() property. FileAttributes is an enumerator with the following members: Archive, Compressed, Device, Directory, Encrypted, Hidden, Normal, NotContentIndexed, Offline, ReadOnly, ReparsePoint, SparseFile, System, and Temporary. |
|
||
Previous | Copyright © 2005-2016, FunctionX | |
|