2

I want to get a time of all files that are in this folder ("/sdcard/Files/"). And then I want to delete all the files that have more than one hour.

Is there any method to do it?

Brian Tompsett - 汤莱恩
  • 5,438
  • 68
  • 55
  • 126
HaOx
  • 1,799
  • 5
  • 24
  • 36

1 Answers1

3
    File dir = new File("/sdcard/Files/");
    File[] files = dir.listFiles();
    for (int i = 0; i < files.length; ++i){
        long lastTime = files[i].lastModified();
        Date nowDate = new Date();
        long nowTime = nowDate.getTime();
        if (nowTime - lastTime > 60*60*1000){
            files[i].delete();
        }
     }

I hope it can help you.

spmno
  • 685
  • 6
  • 12