The files are not ordered in any specific way. You will need to sort them yourself. If you need help with it I can show you some code that will sort the list based on the last modified attribute.
Sub Process_Globals
Type FileAndTime(Name As String, Time As Long)
End Sub
Sub Globals
End Sub
Sub Activity_Create(FirstTime As Boolean)
Dim files As List
files = ListFilesByDate(File.DirRootExternal)
For i = 0 To files.Size - 1
Dim fs As FileAndTime
fs = files.Get(i)
Log(fs.Name & ": " & DateTime.Date(fs.Time))
Next
End Sub
Sub ListFilesByDate(Folder As String) As List
Dim files As List
files = File.ListFiles(Folder)
Dim sortedFiles As List
sortedFiles.Initialize
For i = 0 To files.Size - 1
Dim fs As FileAndTime
fs.Name = files.Get(i)
fs.Time = File.LastModified(Folder, fs.Name)
sortedFiles.Add(fs)
Next
sortedFiles.SortType("Time", False)
Return sortedFiles
End Sub
Compiling code. Error
Error compiling program.
Error description: Unknown member: sorttype
Occurred on line: 367
sortedFiles.SortType("Time", False)
Word: sorttype
fileList=File.ListFiles(DataFolder)
If fileList.Size > 0 then
sortedFileList=fileList.Sort(False)
Else
MsgBox("No file", "File read")
End If
I think something is wrong here. Could you try this?Erel,
Given this code:
fileList=File.ListFiles(DataFolder)
sortedFileList=fileList.Sort(False)
compiler says "cannot assign void value" flagging the last line. Don't know what I'm missing. Both variables are defined as lists.
Thanks!
fileList=File.ListFiles(DataFolder)
fileList.sort(false)
sortedFileList.addall(fileList)
Or perhaps this:But do you really need a second list with the content of the sorted list ?B4X:fileList=File.ListFiles(DataFolder) fileList.sort(False) sortedFileList = fileList
After fileList.sort(False), fileList is sorted.
Best regards.