Basic FileLen function that supports file sizes > 4GB?

This was observed with Libre Office 4.2.2.1, Basic macros.

This was observed in both Linux (Fedora fc20) and Windows 7.

The current FileLen function in basic returns the file size value as a ‘long’; the leads to unpredictable results if the file size is larger (including negative file sizes if cast into a ‘double’). From within Basic, there is no way to know if this has happened which can lead to some very strange behavior. Is there a different function available that can deal with larger file? I believe that within Libre Office (at some level) the correct file size is available, since the File dialog running on Linux shows file sizes larger than 4GB; any way to get this information in the Basic macro environment?

I created a work-around by executing a shell command in the local system but this is ugly and I would like to find a cleaner solution if possible.

I wanted to check before logging this as a bug.

One can create a Basic function that’s bridged to a Python function, therefore overcoming the 2 Gio file size limit up to approx. 856,484 Gio. This FileLen() extension operates across (Libre/Open)Office products as well as across all supported platforms.

A french example is available from [Python] (bien) débuter avec LibreOffice ou OpenOffice (Consulter le sujet) • Forum OpenOffice LibreOffice NeoOffice

Example code:
MsgBox _Basic.devTools.FileLen(“C:\pagefile.sys”), “Quite a big file !”

I’m also struggling to find an answer, googling for hours, but I’m afraid a neat function is not available yet :(.
So, as ugly as your shell command work-around may look, you might as well stick with it.

The “closest” piece of code I got, I found here:

 Sub Test() 
    proprietesFichier_getFile "C:\Documents and Settings\mimi\dossier\Nom Classeur.xls" 
    proprietesFichier_getFile "C:\dossier\monAppli.exe" 
    proprietesFichier_getFile "C:\dossier\le fichier.pdf" 
End Sub 

Sub proprietesFichier_getFile( Fichier As String ) 
  Dim oObj As Object , Cible As Object 
  Dim Valeur As Object 
  Dim Resultat As String 
  
  oObj = createUnoService("com.sun.star.bridge.OleObjectFactory")  
  Cible = oObj.createInstance("Scripting.fileSystemObject") 
  Valeur = Cible.GetFile(Fichier) 
  
  Resultat = "Chemin : " & Valeur.ParentFolder.Path & Chr(10) & Chr(10) & _ 
    "Chemin court : " & Valeur.shortpath & Chr(10) & Chr(10) & _ 
    "Nom court : " & Valeur.ShortName & Chr(10) & Chr(10) & _ 
    "Date creation : " & CDate( Valeur.DateCreated.Value ) & Chr(10) & Chr(10) & _ 
    "Date derniere modification : " & CDate( Valeur.DateLastModified.Value ) & Chr(10) & Chr(10) & _ 
    "Date dernier acces : " & CDate( Valeur.DateLastAccessed.Value ) & Chr(10) & Chr(10) & _ 
    "Taille fichier : " & Valeur.Size & " octets" & Chr(10) & Chr(10) & _ 
    "Type fichier : " & Valeur.Type & Chr(10) & Chr(10) & _ 
    "Extension fichier : " & Cible.GetExtensionName(Valeur) & Chr(10) & Chr(10) & _ 
    "Nom fichier sans extension : " & Cible.GetBaseName(Valeur) & Chr(10) & Chr(10) & _ 
    "Nom fichier : " & Cible.GetFileName(Valeur) & Chr(10) & Chr(10) & _ 
    "Chemin et nom complet : " & Cible.GetAbsolutePathName(Valeur) 
  
  MsgBox Resultat 
  
End Sub

Which is a bit elaborate, and alas fails reaching:

Cible = oObj.createInstance("Scripting.fileSystemObject")

which i suppose only works in M$ Visual Basic.

In the meanwhile however, my solution lies in this simple piece of code (with imperfect function FileLen() returning a “long” ) inspired from here:

Function dFileSizeInKb(sMediaFilePath) as Double

            Dim dMediaFileLength as double

		dMediaFileLength = FileLen(sMediaFilePath)
		if dMediaFileLength < 0 then
			dMediaFileLength = 2^32 + dMediaFileLength
		end if

            dFileSizeInKb = dMediaFileLength

End Function

BTW, Could you please share this shell command work-around of yours. This would be much apreciated.

Thanks very much in advance