Skip to content Skip to sidebar Skip to footer

Get File Creation Time

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?

Solution 1:

    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.


Post a Comment for "Get File Creation Time"