Yes, you'll need a programmatic way to find out if a glob pattern is absolute. This can be done as follows:
for (String glob : new String[] { "../path/*.txt", "c:/../path/*.txt", "/../path/*.txt" }) {
System.out.println(glob + ": is " + (new File(glob).isAbsolute() ? "absolute" : "relative"));
}
On Windows this will output
../path/*.txt: is relative
c:/../path/*.txt: is absolute
/../path/*.txt: is relative
On unix the last is absolute. If you know the glob pattern is relative, prepend the special directory to it. After that you'll have an absolute path for all glob patterns and can use that to specify it for the search.
EDIT 1
As per you comment, you can do the following. But you can also mix and match nio and io. You should know that java.io.File.isAbsolute() only checks the file path FORMAT, not if the file actually exists, to determine if it's in absolute or relative form. It does that in a platform specific manor.
String baseDir = "c:/BaseDir/";
for (String glob : new String[] { "../path/*.txt", "c:/../path/*.txt", "/../path/*.txt" }) {
File file = new File(glob);
if (!file.isAbsolute()) {
file = new File(baseDir, glob);
}
System.out.println(file.getPath() + ": is " + (file.isAbsolute() ? "absolute" : "relative"));
}
this will print
c:\BaseDir\..\path\*.txt: is absolute
c:\..\path\*.txt: is absolute
c:\BaseDir\..\path\*.txt: is absolute
you will still have to do the globbing yourself or use any methods described in the post you mentioned (How to find files that match a wildcard string in Java?)