+
+ /*
+ * This method returns the basename of the first --append or --open value.
+ * Used primarily for substitutions in output filenames.
+ */
+ public String getBasename()
+ {
+ return getDirBasenameOrExtension(false, false, false);
+ }
+
+ /*
+ * This method returns the basename of the first --append or --open value.
+ * Used primarily for substitutions in output filenames.
+ */
+ public String getExtension()
+ {
+ return getDirBasenameOrExtension(false, true, false);
+ }
+
+ /*
+ * This method returns the dirname of the first --append or --open value.
+ * Used primarily for substitutions in output filenames.
+ */
+ public String getDirname()
+ {
+ return getDirBasenameOrExtension(true, false, false);
+ }
+
+ public String getDirBasenameOrExtension(boolean dirname,
+ boolean extension, boolean absoluteDirname)
+ {
+ String filename = null;
+ String appendVal = getValue(Arg.APPEND);
+ String openVal = getValue(Arg.OPEN);
+ if (appendVal != null)
+ filename = appendVal;
+ if (filename == null && openVal != null)
+ filename = openVal;
+ if (filename == null)
+ return null;
+
+ File file = new File(filename);
+ if (dirname)
+ {
+ return FileUtils.getDirname(file);
+ }
+ return extension ? FileUtils.getExtension(file)
+ : FileUtils.getBasename(file);
+ }
+
+ /*
+ * Checks if there is an Arg with Opt
+ */
+ public boolean hasArgWithOption(Opt o)
+ {
+ for (Arg a : getArgKeys())
+ {
+ if (a.hasOption(o))
+ return true;
+ }
+ return false;
+ }