public static void deleteUnlistedFiles(File folder,Set<String> dependecyFiles){
  if (!folder.exists() || (dependecyFiles == null)) {
    return;
  }
  for (  File resource : folder.listFiles()) {
    if (resource.isDirectory()) {
      deleteUnlistedFiles(resource,dependecyFiles);
    }
 else     if (!dependecyFiles.contains(resource.getName())) {
      resource.delete();
    }
  }
}

public static void deleteUnlistedFiles ( File folder , Set < String > dependecyFiles ) { if ( ! folder . exists ( ) || ( dependecyFiles == null ) ) { return ; } for ( File resource : folder . listFiles ( ) ) { if ( resource . isDirectory ( ) ) { deleteUnlistedFiles ( resource , dependecyFiles ) ; } else if ( ! dependecyFiles . contains ( resource . getName ( ) ) ) { resource . delete ( ) ; } } }
deletes files from targetfolder that are not in filelist .
