Share via


How to: Determine a File's Size in Visual Basic

The GetFileInfo method can be used to get a FileInfo object, which contains information about the specified file.

You can use the Length property to determine the size of the file in bytes.

Note

Your computer might show different names or locations for some of the Visual Studio user interface elements in the following instructions. The Visual Studio edition that you have and the settings that you use determine these elements. For more information, see Visual Studio Settings.

To determine a file's size

  • Use the GetFileInfo method to return a FileInfo object for the file, which can be queried for information. This example gets a FileInfo object for Testfile.txt and uses the Length property to display the size of the file in bytes.

    Dim infoReader As System.IO.FileInfo
    infoReader = My.Computer.FileSystem.GetFileInfo("C:\testfile.txt")
    MsgBox("File is " & infoReader.Length & " bytes.")
    

See Also

Tasks

How to: Determine a File's Attributes in Visual Basic

Reference

FileSystem

GetFileInfo

Other Resources

File, Directory, and Drive Properties in Visual Basic