Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determining file size in VB.NET

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.

like image 255
John Wheal Avatar asked Apr 16 '12 14:04

John Wheal


People also ask

How do you determine the size of a file?

Click the file or folder. Press Command + I on your keyboard. A window opens and shows the size of the file or folder.

What do you mean by get file size in Visual Basic?

Sometimes in VB.NET programs we want to get the number of bytes in a file. FileInfo can return the file size. This value is a Long, but can usually be safely to an Integer.

How do I convert MB to file size?

You can retrieve the length of the file with File#length(), which will return a value in bytes, so you need to divide this by 1024*1024 to get its value in mb.

How do I check the size of a file in Terminal?

What we need is to open the terminal and type du -sh file name in the prompt. The file size will be listed on the first column. The size will be displayed in Human Readable Format. This means we can see file sizes in Bytes, Kilobytes, Megabytes, Gigabytes, etc.


2 Answers

Dim myFile As New FileInfo("file.txt")
Dim sizeInBytes As Long = myFile.Length
like image 153
Dennis Traub Avatar answered Sep 28 '22 18:09

Dennis Traub


For anyone looking for the shorter VB version:

FileLen("file.txt")

https://msdn.microsoft.com/en-us/library/microsoft.visualbasic.filesystem.filelen

like image 45
Slai Avatar answered Sep 28 '22 19:09

Slai