JAL-629 Added --opennew --nonews --nosplash. Added java globbing for = e.g. --open...
[jalview.git] / src / jalview / util / FileUtils.java
index 9aa27f9..63af0bc 100644 (file)
@@ -26,9 +26,16 @@ public class FileUtils
    */
   public static List<File> getFilesFromGlob(String pattern)
   {
+    return getFilesFromGlob(pattern, true);
+  }
+
+  public static List<File> getFilesFromGlob(String pattern,
+          boolean allowSingleFilenameThatDoesNotExist)
+  {
+    pattern = substituteHomeDir(pattern);
     List<File> files = new ArrayList<>();
     /*
-     * For efficiency of the Files.walkFileTree, let's find the longest path that doesn't need globbing.
+     * For efficiency of the Files.walkFileTree(), let's find the longest path that doesn't need globbing.
      * We look for the first glob character * { ? and then look for the last File.separator before that.
      * Then we can reset the path to look at and shorten the globbing pattern.
      * Relative paths can be used in pattern, which work from the pwd (though these are converted into
@@ -94,7 +101,7 @@ public class FileUtils
     {
       // no wildcards
       File f = new File(pattern);
-      if (f.exists())
+      if (allowSingleFilenameThatDoesNotExist || f.exists())
       {
         files.add(f);
       }
@@ -110,4 +117,10 @@ public class FileUtils
             .collect(Collectors.toList());
   }
 
-}
\ No newline at end of file
+  public static String substituteHomeDir(String path)
+  {
+    return path.startsWith("~" + File.separator)
+            ? System.getProperty("user.home") + path.substring(1)
+            : path;
+  }
+}