Android Question Time the folder

T201016

Active Member
Licensed User
Longtime User
Hi!
Can I recover data such as the date / time I created any folder in Java?
Any suggestions? :)
 

T201016

Active Member
Licensed User
Longtime User
Hello,
thanks for taking the moment :)

I have written a small piece of code which does a recursive search within all subdirectories and returns
the latest modification date. It does a deep search,
so you may not want to run it on the root directory or so.
Here is the code (I have not tested):

B4X:
private static long getLatestModifiedDate(File dir) {
    File[] files = dir.listFiles();
    long latestDate = 0;
    for (File file : files) {
        long fileModifiedDate = file.isDirectory()
                ? getLatestModifiedDate(file) : file.lastModified();
        if (fileModifiedDate > latestDate) {
            latestDate = fileModifiedDate;
        }
    }
    return Math.max(latestDate, dir.lastModified());
}

Or

B4X:
import java.io.File;
import java.io.IOException;
import java.util.Date;
import java.util.concurrent.TimeUnit;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

protected Date folderCreatedDate(String folderName) {
          long date = 0;
          File fl = new File(folderName);
          if (fl.isDirectory())
            if (fl.exists())
               date = fl.lastModified();
          return new Date(date);
   }
  
  
protected long getFolderSize(File folder){                 
    long foldersize = 0;
 
    File[] filelist = folder.listFiles();
    for(int i = 0; i < filelist.length; i++)
     {
       if(filelist[i].isDirectory())
         foldersize += getFolderSize(filelist[i]);
        else
           foldersize += filelist[i].length();
     }
  return foldersize;
}


protected Date folderCreatedDate(String folderName) {
          long date = 0;
          File fl = new File(folderName);
          if (fl.isDirectory())
            if (fl.exists())
               date = fl.lastModified();
          return new Date(date);
   }

the problem is how to properly apply this piece of code in B4A (If Java ... End If)?
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

T201016

Active Member
Licensed User
Longtime User
Well, you're basically right. But I have already solved the problem.
Thank's DonManfred ;)
 
Upvote 0
Top