VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Get file size up to a terabyte

by Alex Kail (1 Submission)
Category: Files/File Controls/Input/Output
Compatability: Visual Basic 3.0
Difficulty: Beginner
Date Added: Wed 3rd February 2021
Rating: (2 Votes)

Returns the file size of the file name passed in the format the user specifies

Inputs
File name, and return type (bytes, kilobytes, etc)
Code Returns
File size (double) in the format specified in the arguments
Side Effects
None to my knowledge
API Declarations
'Various views for file sizes
Public Enum FileSizeView
fsBytes = -1
fsKilobytes = 0
fsMegabytes = 1
fsGigabytes = 2
fsTerabytes = 3
End Enum

Rate Get file size up to a terabyte

Function FileSize(ByVal strFile As String, Optional ByVal ReturnAs As FileSizeView = fsBytes) As Double
 'Purpose: Returns the file size of the file name passed in the format the user specifies
 Dim dblLen As Double, lngIndex As Long
 'If file doesn't exist, abort
 If Dir(strFile) = Empty Then
  FileSize = 0
  Exit Function 'Abort
 End If
 'Returns the file length in bytes
 dblLen = FileLen(strFile)
 'Calculate to the file size view passed
 For lngIndex = 0 To ReturnAs
  dblLen = dblLen / 1024
 Next
 'Return the file size
 FileSize = dblLen
End Function

Download this snippet    Add to My Saved Code

Get file size up to a terabyte Comments

No comments have been posted about Get file size up to a terabyte. Why not be the first to post a comment about Get file size up to a terabyte.

Post your comment

Subject:
Message:
0/1000 characters