How do I determine the size of a text file?
I know that I could just count characters, but the file will be several MB's large.
How do I determine the size of a text file?
I know that I could just count characters, but the file will be several MB's large.
Dim myFile As New FileInfo("file.txt")
Dim sizeInBytes As Long = myFile.Length
Dim size As Long = FileLen("file.txt")
https://msdn.microsoft.com/en-us/library/microsoft.visualbasic.filesystem.filelen
The use of file
can be dangerous as it is also the name of a class.
It is better to code it as follows:
Dim myFile As New FileInfo("file.txt")
Dim sizeInBytes As Long = myFile.Length
The code from the other answer does not check the correct size of the file:
Dim myFile As New FileInfo("file.txt")
Dim sizeInBytes As Long = MyFile.Length
Try this code instead
Dim infoReader As System.IO.FileInfo = _
My.Computer.FileSystem.GetFileInfo("C:\testfile.txt")
MsgBox("File C:\testfile.txt is " & infoReader.Length & " bytes.")
It is from How to: Determine a File's Size in Visual Basic (MSDN).