Hello,
The below code is checking files in a selected folder and uses the Java code I found here in the forum.
Why do I see the JavaObject contents as Items in the Log but not in the Listview?
Perhaps I'm doing something wrong, could someone point me how to fix this?
What I need is the full pathname including filename, Filenam, Size, and the date of the file. The last 3 do not need to be in the Listview necessarily, they could be in a variable so they all can be added to a Database.
Thanks for any help.
The below code is checking files in a selected folder and uses the Java code I found here in the forum.
Why do I see the JavaObject contents as Items in the Log but not in the Listview?
Perhaps I'm doing something wrong, could someone point me how to fix this?
B4X:
Sub GetTheFolderContents (fldr As String)
'Log("fldr=" & fldr)
Dim folders As List
folders.Initialize
folders.Add(fldr)
fList.Initialize
Dim JO As JavaObject = Me
Dim FilePath As String
Do While folders.Size > 0
fldr = folders.Get(0)
folders.RemoveAt(0)
Label5TotalNrFiles.Text = fList.Size
Sleep(0)
Dim entries As List = File.ListFiles(fldr)
If entries.IsInitialized Then
For Each x As String In entries
If File.IsDirectory(fldr, x) Then
folders.Add(File.Combine(fldr, x)) ' Found a subfolder
Else
FilePath = (fldr & "\" & x)
JO.RunMethod("FileDetails",Array(FilePath))
'Log("FileDetails: " & Array(FilePath))
'try to get each item from returned javaobject array
Dim myArray(4) As String
myArray = Array As String(FilePath)
'For i = 0 To myArray.Length - 1
' Dim currentItem As String = myArray(i)
' Dim itemNumber As Int = i + 1 ' Adding 1 to get the actual item number (1-based index)
' Log("Item number: " & itemNumber & ", Item: " & currentItem)
' ListView1.Items.Add("Item number: " & itemNumber & ", Item: " & currentItem)
'Next
For Each item As String In myArray
' Do something with the current item, for example, print it:
ListView1.Items.Add("Item: " & item)
Log("Item: " & item)
Next
End If
Next
End If
Loop
End Sub
#if java
import java.io.File;
import java.io.IOException;
import java.text.ParseException;
import java.util.Date;
public static void FileDetails(String filePath) {
File file = new File(filePath); //with \ escape pattern for backslashes
System.out.println(file.getAbsolutePath());
System.out.println(file.getName());
System.out.println(file.length()); //Size
System.out.println(new Date(file.lastModified()));
//System.out.println(file.getAbsolutePath() + "," + file.getName() + "," + file.length() + "," + new Date(file.lastModified()));
}
#End If
What I need is the full pathname including filename, Filenam, Size, and the date of the file. The last 3 do not need to be in the Listview necessarily, they could be in a variable so they all can be added to a Database.
Thanks for any help.
Last edited: