File length of large files

G

Guest

Hello,

I have a problem retrieving file length of large files greater then 2 GB
using function FileLen(strFileName). This function returns long values with 4
Byte, delivering negative values for file size above 2 GB and recycles above
4 GB.
Is there another way to retrieve the filesize in excel working for large
files.
I have a list of filenames in Excel and need to do some calculations and
reporting on the filesize.
Any help appreciated. Thanks.

Stefan Hoyos
 
N

NickHK

For reliable results on large file, resort to the API calls.
Example from the API-Guide, http://www.allapi.net/

Private Const GENERIC_READ = &H80000000
Private Const FILE_SHARE_READ = &H1
Private Const OPEN_EXISTING = 3

Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA"
(ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal
dwShareMode As Long, lpSecurityAttributes As Any, ByVal
dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal
hTemplateFile As Long) As Long
Private Declare Function GetFileSizeEx Lib "kernel32" (ByVal hFile As Long,
lpFileSize As Currency) As Boolean
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long)
As Long

Private Sub CommandButton1_Click()

Dim hFile As Long, nSize As Currency, sSave As String

'open the file
hFile = CreateFile("c:\autoexec.bat", GENERIC_READ, FILE_SHARE_READ, ByVal
0&, OPEN_EXISTING, ByVal 0&, ByVal 0&)
'get the filesize
GetFileSizeEx hFile, nSize

'close the file
CloseHandle hFile

MsgBox "File Size:" + Str$(nSize * 10000) + " bytes"

End Sub

NickHK
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top