protected void cleanOutOldAvatars ( File directory , int maxLifeInDays ) { if ( directory != null ) { if ( mCleanedDirectories . contains ( directory . getAbsolutePath ( ) ) ) { return ; } long oldestTimeAllowed = System . currentTimeMillis ( ) - maxLifeInDays * TimeUnit . DAYS . toMillis ( maxLifeInDays ) ; File [ ] files = directory . listFiles ( ) ; if ( files != null ) { for ( File file : files ) { if ( file . getName ( ) . startsWith ( DEFAULT_AVATAR_FILE_PREFIX ) && file . lastModified ( ) < oldestTimeAllowed ) { file . delete ( ) ; } } } } }
Delete all files for user that is older than maxLifeInDays