Solved

VB.Net Getting file size in MBs/KB's

Posted on 2012-12-26
2
2,989 Views
Last Modified: 2012-12-26
Hi Experts.  
Can some please explain why I keep getting the answer 13 when the actual file size is 1.3G and how I would get MB's and KB's

Dim filename As String
filename = ("C:\backup.pst")
MsgBox(filename.Length)

I've tried converting to integer and long but then I just get 0

Thanks
0
Comment
Question by:PNRT
  • 2
2 Comments
 
LVL 74

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
Comment Utility
Because you are asking for the length of a string. "C:\backup.pst" is 13 characters in length. To get file size do:

Dim info As New System.IO.FileInfo(@"C:\backup.pst")
MsgBox(info.Length)

Open in new window

0
 
LVL 74

Expert Comment

by:käµfm³d 👽
Comment Utility
P.S.

The Length property will give you the count of bytes for the file. To convert to human quantities you will have to do a bit of math:

info.Length / 1024  ' kilobytes
info.Length / 1048576 ' megabytes
info.Length / 1073741824 ' gigabytes

Open in new window

0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now