*/
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
{
// no wildcards
File f = new File(pattern);
- if (f.exists())
+ if (allowSingleFilenameThatDoesNotExist || f.exists())
{
files.add(f);
}
.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;
+ }
+}