Well, try this:
Option Explicit
Sub createFileList
Dim oFolderDialog As Object, oUcb As Object
Dim sStartFolder As String
Dim aList As Variant, aRes As Variant
Dim nRow As Long, i As Long
Dim sFullName As String, sExt As String, sFile As String, sPath As String, sFolder As String
Dim oDoc As Variant, oSheet As Variant
Globalscope.BasicLibraries.LoadLibrary("Tools")
sStartFolder = ""
oFolderDialog = CreateUnoService("com.sun.star.ui.dialogs.FolderPicker")
oUcb = createUnoService("com.sun.star.ucb.SimpleFileAccess")
If oUcb.Exists(GetPathSettings("Work")) Then oFolderDialog.SetDisplayDirectory(GetPathSettings("Work"))
If oFolderDialog.Execute() = 1 Then
sStartFolder = oFolderDialog.GetDirectory()
If oUcb.Exists(sStartFolder) Then sStartFolder = ConvertFromUrl(sStartFolder)
End If
If sStartFolder = "" Then Exit Sub
aList = ReadDirectories(sStartFolder, True, True, False)
ReDim aRes(UBound(aList))
nRow = -1
sFolder = ""
For i = LBound(aList) To UBound(aList)
sFullName = ConvertFromURL(aList(i,0))
sExt = LCase(GetFileNameExtension(sFullName))
If sExt = "jpeg" Or sExt = "jpg" Or sExt = "png" Then
sFile = FileNameOutOfPath(sFullName, GetPathSeparator())
sPath = DirectoryNameOutOfPath(sFullName, GetPathSeparator())
If sPath = sFolder Then
aRes(nRow)(1) = aRes(nRow)(1) + "|" + sFile
Else
sFolder = sPath
nRow = nRow + 1
aRes(nRow) = Array(sFolder, sFile)
EndIf
EndIf
Next i
If nRow < 0 Then Exit Sub
ReDim Preserve aRes(nRow)
oDoc = CreateNewDocument("scalc")
oSheet = oDoc.getSheets().getByIndex(0)
oSheet.getCellRangeByPosition(0,0,1,nRow).setDataArray(aRes)
End Sub