Visual Basic Explorer
Visual Basic Explorer
 Navigation
 Home


 Coding
 Source Code

 FAQ Center

 VB Tips

 Downloads

 ToolBox

 Tutorials

 VB Games

 VB News

 VB Award

 VB Forums



 Affiliates
 Planet Source Code

 Rent a Coder

 DirectX4VB


 Misc
 Search

 Feedback

 Advertise

 About


Need to hire
a VB coder?

Please support our sponsor:

 Home 
 Site Map 
 Forums 
 News 
 Feedback 

Get File Size


This is an easy way to get the file size of any file a user might select. Lets assume you have a form with a directory list box called mydir and a file list box named myfile. The user can scroll to any directory on their hard drive, select a file from the file list box and the program will tell them the size of that file. Heres the code:

Private Sub cmdShowFileSize_Click()
Dim strOldFile As String
Dim strOldSize As String
Dim strMyDir As String
Dim strMyFile As String

'Update the following with your directory and file
'info or use App.Path. This sample does not include
'error checking.

strMyDir = "c:\windows\desktop"
strMyFile = "readme.txt"

  strOldFile = strMyDir & "\" & strMyFile
  strOldSize = FileLen(strOldFile)
  
  lblFileSize.Caption = "The file " & strOldFile & " is " & _
  Format(strOldSize, "#,##0") & " bytes in size."

End Sub

--------------------------------------------------------------------
Note: Code updated by Burt Abreu from an original 
tip submitted by Greg Kamer at gkamer@agritel.net
--------------------------------------------------------------------

Download VB6 Sample





Home | About | What's New | Source Code | FAQ | Tips & Tricks | Downloads | ToolBox | Tutorials | Game Programming | VB Award | Search | VB Forums | Feedback | VBNews | Copyright & Disclaimer | Advertise | Privacy Policy |

Quick searches: Site Search | Advanced Site Search 

Copyright 2002 by Exhedra Solutions, Inc.
By using this site you agree to its terms and conditions
VB Explorer and VBExplorer.com are trademarks of Exhedra Solutions, Inc.