Finding Out the Size of a File the File Len Function

If you want to check whether a certain file will fit on a diskette, you should use the FileLen function in the following form:


Pathname is a string that specifies the file you want to work with and may include the drive and folder where the file resides. The FileLen function returns the size of a file in bytes. If the file is open, Visual Basic returns the size of the file when it was last saved.

Suppose that you want to find out the total size of all the files that store the configuration settings in the Windows directory.

1. Insert into the current project a new module and rename it FileLenFunction.

2. Enter the TotalBytesIni procedure in the Code window:

Sub TotalBytesIni()

Dim iniFile As String Dim allBytes As Long iniFile = Dir("C:\WINDOWS\*.ini") allBytes = 0

allBytes = allBytes + FileLen("C:\WINDOWS\" & iniFile) iniFile = Dir


Debug.Print "Total bytes: " & allBytes End Sub

0 0

Post a comment