I want to check the size of the file(s) the user selects using the OpenFileDialog in IBM Domino designer. For this I am calling the function FileLen. This works fine with normal files. But with a big file (over 2 GB), I always get a negative long returned. Is there a way to get the correct size of such big files? The problem is reported on the web, but no solution was suggested! I started with the following code (Got it from this blog):
On Error Goto ErrorHandler
Dim pathName As String, fileName As String
Dim verLen As Long
pathName$ = "C:\Users\Maheshwaran Thirumoo\Desktop\test\*.*"
fileName$ = Dir$(pathName$)
Do While fileName$ <> ""
verLen = Filelen("C:\Users\Maheshwaran Thirumoo\Desktop\test\" +fileName$)
Print + "====="& fileName$ "====" & verLen
fileName$ = Dir$()
Loop
Exit Sub
ErrorHandler:
Print "Error @ line # : " & Cstr(Erl) & "<br> Error is : " & Error
Exit Sub
FileLen
returns a long data type. This can be a value from -2,147,483,648 to 2,147,483,647.
So with that command you won't be able to do it. LotusScript is quite an old language and still based on 32bit systems (late 90's).
You could use LS2J to have Java get the file size and pass it back to LotusScript, but you may hit other limitations on variable sizes.
Here is an example I did that works:
1. Created a Java class as follows.
import java.io.File;
public class FileSizeHelper {
public static String getFileSize(String filename) {
File file = new File(filename);
return "" + file.length();
}
}
2. Create a directory c:\notes\test and put the FileSizeHelper.class file into it.
3. Edit the Notes.ini and add the following line.
JavaUserClasses=c:\notes\test
4. Restart your Notes client. Open designer and create a LotusScript agent as follows:
Option Public
Option Declare
UseLSX "*javacon"
Sub Initialize
dim mySession as New JavaSession()
Dim myClass As Variant
Dim myObject As variant
Dim answer As String
Set myClass = mySession.Getclass("FileSizeHelper")
Set myObject = myClass.createObject
answer = myClass.getFileSize("<PUT FILENAME HERE>")
MsgBox answer
End Sub
5. Change <PUT FILENAME HERE>
to the path to the file you want to get the file size off. It will follow the Java convention on referencing a file. e.g. "C:\\temp\\test.txt", "/temp/test.txt".
When you run it, it should show a string of the file size.