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,753
  • 72
  • 57
  • 129
HaOx
  • 1,839
  • 6
  • 26
  • 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
  • 805
  • 7
  • 13