How to Get a File Size Using VB.NET
In this article I describe how to get a file size.
Check if a File Exists
The Exists property returns true if a file exists. The following code snippet returns true if a file already exists.
Dim exists As Boolean = fi.Exists
Get a file size
The Length property returns the size of a file in bytes. The following code snippet returns the size of a file.
Imports System.IO
Module Module1
Sub Main()
Dim fileName As String = "C:\Temp\MaheshTXFI.txt"
Dim fi As New IO.FileInfo(fileName)
Dim exists As Boolean = fi.Exists
If fi.Exists Then
Console.WriteLine("File exists")
End If
' Get file size
Dim size As Long = fi.Length
Console.WriteLine("File Size in Bytes: {0}", size)
Console.ReadLine()
End Sub
End Module
Output: