How to: Get Information About a File in Visual Basic
The My.Computer.FileSystem.GetFileInfo Method can be used to easily determine information about a file's properties. Properties of the FileInfo object include attributes, creation time, directory, directory name, whether it exists, extension, full name, last access time, last write time, length, and name.
An exception is not thrown if the file does not exist; rather, it is thrown the first time the object's properties are accessed.
The options available in dialog boxes, and the names and locations of menu commands you see, might differ from what is described in Help, depending on your active settings or edition. This Help page was written with General Development Settings in mind. To change your settings, choose Import and Export Settings on the Tools menu. For more information, see Visual Studio Settings.
To get information about a file
Use the GetFileInfo method to retrieve a FileInfo object that can be examined to determine its properties. The following example retrieves a FileInfo object for the file MyLogFile.log.
Examine the FileInfo object to extract the information you need. The following lines of code report the file's full name, last access time, and length.
The following conditions may cause an exception:
The path name is malformed. For example, it contains invalid characters or is only white space (ArgumentException).
The file does not exist or is Nothing (ArgumentNullException).
The path contains a colon in the middle of the string (NotSupportedException).
The path is too long (PathTooLongException).
The user lacks necessary permissions (SecurityException).
The user lacks ACL (access control list) access to the file (UnauthorizedAccessException).