Returns a Long or a Large specifying the length of a file.
sizeLarge = FileLen ([Pathname$]) *
sizeInt = FileLen% ([Pathname$])
sizeLarge:int64
sizeInt:int32
* actually returns a 32-bit Integer - see Known Issues below
The optional pathname argument is a string expression that specifies a file name. The pathname may include the directory or folder.
Without an argument the function returns the Date for the last file accessed using Dir().
OpenW 1
Global d$, p1 As Int32
// Get the path for GfaWin32.exe
Local d$ = GetSetting("\\HKEY_CLASSES_ROOT\Applications\GfaWin32.exe\shell\open\command", , "")
If Left(d$, 1) = #34 Then d$ = Mid(d$, 2)
p1 = InStr(d$, #34) : If p1 <> 0 Then d$ = Left(d$, p1 - 1)
// Display File Date information
Print "The length of GfaWin32.exe in bytes is: "; FileLen(d$)
// The same results can be achieved through the FileSystemObject
Global Object f, fs
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFile(d$)
Print "The length of GfaWin32.exe in bytes is: "; f.size
Do : Sleep : Until Me Is Nothing
Set f = Nothing : Set fs = Nothing
CloseW 1
FileLen% is GFA-BASIC 16 compatible, because it returns a 32-bit integer. However, it will return the wrong result for files larger than 2 GB.
It has been reported that, on some computers, FileLen returns a 32-bit Integer, not a Large 64-bit integer; it has also been reported that this behaviour can be intermittent, even on the same computer. What appears to be happening is GB32 uses FindFirstFile() to retrieve the file length, namely through the FileSizeHi and FileSizeLo DWord (or Long) properties of the Win32_Find_Data object: when FileSizeLo is returned as a positive value, then GB32 returns the correct file length; however, when FileSizeLo is negative, GB32 ignores the FileSizeHi and just returns the negative FileSizeLo value.
If you encounter this problem, use the Windows FileSystemObject as shown below as a workaround to get the file length of large files:
Dim myFSO As Object, myFile As Object
Set myFSO = CreateObject("Scripting.FileSystemObject")
Set myFile = myFSO.getfile("[Full_File_Path]")
Print myFile.size
FileDateTime(), FileDateTimeAccess(), FileDateTimeCreate(), SetFileDateTime, SetFileDateTimeAccess, SetFileDateTimeCreate
{Created by Sjouke Hamstra; Last updated: 15/12/2014 by James Gaite}