public static void deleteOldFiles ( String dirPath , int olderThanMinute ) { File folder = new File ( dirPath ) ; if ( folder . exists ( ) ) { File [ ] listFiles = folder . listFiles ( ) ; long eligibleForDeletion = System . currentTimeMillis ( ) - ( olderThanMinute * 60 * 1000L ) ; for ( File listFile : listFiles ) { if ( listFile . lastModified ( ) < eligibleForDeletion ) { if ( ! listFile . delete ( ) ) { logger . error ( "Unable to delete file %s" , listFile ) ; } } } } }
Delele old files