Question

I have a timer that looks at a certain directory each hour and pull the contents of that directory for processing. To remove 24 hour duplication, I'm trying to figure out a way to only pull 'new' files for processing. ("new" being older than 24 hours).

One option is to write a custom Comparator, but I was looking for any other alternative ways.

Idea's or thoughts?

Was it helpful?

Solution 3

I believe I found what I was looking for with commons-io:

Calendar cal = Calendar.getInstance();  
cal.add(Calendar.DAY_OF_MONTH, 1 * -1);  
Date yesterday = cal.getTime();   
System.out.println(yesterday);       

// Test for newer files (2nd param [false] = get newer files)        
String[] files = dir.list( new AgeFileFilter(yesterday,false) );
for ( int i = 0; i < files.length; i++ ) {
    System.out.println(files[i]);
}

OTHER TIPS

To avoid issues with file system time stamp differences I would just put in a folder called something like "processed" and move the files you are done with there. That way you can just read what ever files are present.

Hash the file paths to a map and store with it the time you first time encountered it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top