X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Futil%2FFileUtils.java;h=e62a7d600892584996bed6bdff1aee8aec075757;hb=2acaf6533dd61f649b4394082e0e600b7bc0f62d;hp=f5b370116c7a753e32001e289b7c970188530502;hpb=6d08745a94e4f76d4b124afa83b858be8d843005;p=jalview.git diff --git a/src/jalview/util/FileUtils.java b/src/jalview/util/FileUtils.java index f5b3701..e62a7d6 100644 --- a/src/jalview/util/FileUtils.java +++ b/src/jalview/util/FileUtils.java @@ -130,30 +130,43 @@ public class FileUtils } /* - * This method returns the basename of the first --open or --opennew value. - * Used primarily for substitutions in output filenames. + * This method returns the basename of File file */ public static String getBasename(File file) { + return getBasenameOrExtension(file, false); + } + + /* + * This method returns the extension of File file. + */ + public static String getExtension(File file) + { + return getBasenameOrExtension(file, true); + } + + public static String getBasenameOrExtension(File file, boolean extension) + { if (file == null) return null; - String basename = null; + String value = null; String filename = file.getName(); int lastDot = filename.lastIndexOf('.'); if (lastDot > 0) // don't truncate if starts with '.' { - basename = filename.substring(0, lastDot); + value = extension ? filename.substring(lastDot + 1) + : filename.substring(0, lastDot); } else { - basename = filename; + value = extension ? "" : filename; } - return basename; + return value; } /* - * This method returns the dirname of the first --open or --opennew value. + * This method returns the dirname of the first --append or --open value. * Used primarily for substitutions in output filenames. */ public static String getDirname(File file) @@ -164,7 +177,9 @@ public class FileUtils String dirname = null; try { - dirname = file.getParentFile().getCanonicalPath(); + File p = file.getParentFile(); + File d = new File(substituteHomeDir(p.getPath())); + dirname = d.getCanonicalPath(); } catch (IOException e) { Console.debug(