static public void cleanCache ( Date cutoff , StringBuilder sbuff ) { if ( sbuff != null ) sbuff . append ( "CleanCache files before " ) . append ( cutoff ) . append ( "\n" ) ; File dir = new File ( root ) ; File [ ] children = dir . listFiles ( ) ; if ( children == null ) return ; for ( File file : children ) { Date lastMod = new Date ( file . lastModified ( ) ) ; if ( lastMod . before ( cutoff ) ) { boolean ret = file . delete ( ) ; if ( sbuff != null ) { sbuff . append ( " delete " ) . append ( file ) . append ( " (" ) . append ( lastMod ) . append ( ")\n" ) ; if ( ! ret ) sbuff . append ( "Error deleting " ) . append ( file ) . append ( "\n" ) ; } } } }
Remove all files with date < cutoff .