Get the size of a file
By: Lorenzo Dalla Vecchia Date: 21/10/1998

There are two ways to get the size of a file. If the file is open in your program, use the LOF function:


Where filenumber is the number of the file as specified in the Open statement. Example:

Open "C:\Work\MyFile.Txt" For Input As #1 'Open the file
size = LOF(
                            'Get file size
Close #
                                 'Close the file

If the file is not open in your program, you will need to use the FileLen function:


With filepath replaced by the name and path of the file. To view the size of the file of the above example, but without opening it, we'll type the code:

size = FileLen("C:\Work\MyFile.Txt")

In both examples, the size variable will contain the size, in bytes, of C:\Work\MyFile.Txt.

Click Here!

Visual Basic Programming Zone is a website by Lorenzo Dalla Vecchia.
Webmaster's e-mail:
Hosted by InWind: