question: public static void deleteFilesInDirectory ( final File directory , final FilenameFilter filter , final Logger logger , final boolean recurse , final boolean deleteEmptyDirectories ) throws IOException { if ( null != directory && directory . isDirectory ( ) ) { final File ingestFiles [ ] = directory . listFiles ( ) ; if ( ingestFiles == null ) { throw new IOException ( "Unable to list directory content in: " + directory . getAbsolutePath ( ) ) ; } for ( File ingestFile : ingestFiles ) { boolean process = ( filter == null ) ? true : filter . accept ( directory , ingestFile . getName ( ) ) ; if ( ingestFile . isFile ( ) && process ) { FileUtils . deleteFile ( ingestFile , logger , 3 ) ; } if ( ingestFile . isDirectory ( ) && recurse ) { FileUtils . deleteFilesInDirectory ( ingestFile , filter , logger , recurse , deleteEmptyDirectories ) ; if ( deleteEmptyDirectories && ingestFile . list ( ) . length == 0 ) { FileUtils . deleteFile ( ingestFile , logger , 3 ) ; } } } } }
target:  Deletes all files (not directories) in the given directory (recursive) that match the given filename filter. If any file cannot be deleted then this is printed at warn to the given logger.