No need to answer this question at this time. I found an example of a sort module in the beginners guide I will experiment with. I would like to know why listfiles doesn't normally return files in filename sequence, though.
I'm using the command listfiles to return the filenames of all the files in a directory(folder). The file names include the date it was created. All of the file names are identical except for the date. The problem is that the files names are not always returned in date sequence. Is there a way to get listfiles to sort by name? If not is there an example of how to efficiently sort and array?
I'm using:
B4X:
Public MyList As List
Public MyFile As String
MyList.Initialize
MyList = File.ListFiles(File.DirRootExternal & "/ELSIE/")
MyFile = MyList.Get(0)
This was working fine until today. Now the file I created today is first in the list instead of last.
Tunderin, Thank you for your quick reply. That is the example I found in the beginner's guide. I have tested it and it does what I was looking for. Actually it did more because I have been wanting to sort the names in descending order, too.
DonManfred, thank you very much. This made it so much more easy and I like the returned format better.
Here is all I had to do to get the list, get it sorted, and get the first filename.
B4X:
Dim MyList As List
Dim MyFile As String
MyList.Initialize
MyList = File.ListFiles(File.DirRootExternal & "/ELSIE/")
MyList.Sort(True) 'sorts ascending the list
MyFile=MyList.Get(0)