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.
Click the file or folder. Press Command + I on your keyboard. A window opens and shows the size of the file or folder.
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.
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.
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.
Dim myFile As New FileInfo("file.txt")
Dim sizeInBytes As Long = myFile.Length
For anyone looking for the shorter VB version:
FileLen("file.txt")
https://msdn.microsoft.com/en-us/library/microsoft.visualbasic.filesystem.filelen
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With