file list sort by modified time in android [using sketchware]

217 views Asked by At

im trying to get a file list at the directory "/storage/emulated/0/tmp/subtmp/" then sort it in newest first order./get sorted list stating itself.

enter image description here ^ this is the order I'm trying to achieve.

fourth
third
first
last
second

^this is what i get using, enter image description here OR enter image description here

I tried using lastModified() but it errors, looks like, there is no File data type...

so i tried to fetch view-source: file:///storage/emulated/0/tmp/subtmp/ enter image description here ,which contains modified date & time.
but
that didn't happened..

then i tried using [ls command],

try {

Runtime.getRuntime().exec("ls -t /storage/emulated/0/tmp/subtmp/"); 

edittext.setText("done");

} catch (Exception e ) {

edittext.setText("not done");
ans.setText(e.toString());

}

and

try {

Runtime.getRuntime().exec("ls -t /storage/emulated/0/tmp/subtmp/ > /storage/emulated/0/tmp/output.txt"); //to read and delete

edittext.setText("done");

} catch (Exception e ) {

edittext.setText("not done");
ans.setText(e.toString());

}

but,.. no new files are created on /storage/emulated/0/tmp/


so, is it possible to sort files in sketchware

  • it doesnt have any block to get sorted list
  • it does have a add source directly block
1

There are 1 answers

0
Urvish Shiroya On

I face same issue in show last edited image in first of all [SORT BY TIME], I found solution for me and this code will be help into sort arraylist by time.

Collections.sort(myList, new Comparator<MyObject>() {
  public int compare(MyObject o1, MyObject o2) {
      return o1.getDateTime().compareTo(o2.getDateTime());
  }
});