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?
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?
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.