code: private static File findDirectoryOption(String[] args, String option, String name, boolean needed, boolean allow_dups, boolean create)
          throws ProblemException, ProblemException {
          File dir = null;
          for (int i = 0; i<args.length; ++i) {
              if (args[i].equals(option)) {
                  if (dir != null) {
                      throw new ProblemException("You have already specified the "+name+" dir!");
                  }
                  if (i+1 >= args.length) {
                      throw new ProblemException("You have to specify a directory following "+option+".");
                  }
                  if (args[i+1].indexOf(File.pathSeparatorChar) != -1) {
                      throw new ProblemException("You must only specify a single directory for "+option+".");
                  }
                  dir = new File(args[i+1]);
                  if (!dir.exists()) {
                      if (!create) {
                           throw new ProblemException("This directory does not exist: "+dir.getPath());
                      } else
                      if (!makeSureExists(dir)) {
                          throw new ProblemException("Cannot create directory "+dir.getPath());
                      }
                  }
                  if (!dir.isDirectory()) {
                      throw new ProblemException("\""+args[i+1]+"\" is not a directory.");
                  }
              }
          }
          if (dir == null && needed) {
              throw new ProblemException("You have to specify "+option);
          }
          try {
              if (dir != null)
                  return dir.getCanonicalFile();
          } catch (IOException e) {
              throw new ProblemException(""+e);
          }
          return null;
      }
docs: Scan the arguments to find an option that specifies a directory.
  Create the directory if necessary.