code: public static File findFreeFile(final File dir, String pattern, boolean tryEmptyVar){
          String name = StringUtil.suggest(new Filter<String>(){
              @Override
              public boolean select(String name){
                  return !new File(dir, name).exists();
              }
          }, pattern, tryEmptyVar);
  
          return new File(dir, name);
      }
docs: Finds a free file (i.e non-existing) in specified directory, using specified pattern.
  for example:
  findFreeFile(myDir, "sample${i}.xml", false)
  
  will search for free file in order:
  sample1.xml, sample2.xml, sample3.xml and so on
  
  if tryEmptyVar is true, it it seaches for free file in order:
  sample.xml, sample2.xml, sample3.xml and so on
  
  the given pattern must have variable part ${i}