无法使用PathMatcher查找文件

时间:2016-05-23 15:23:56

标签: java java-8 nio

我正在尝试以下内容==>

String glob = "glob:/Users/CSDSD/Desktop/bahar/bamboo/v1/latest/git/openssl/openssl" + startingDir+File.separatorChar+"**/ms/*.c";
PathMatcher matcher = FileSystems.getDefault().getPathMatcher(glob);
boolean isMatches  = matcher.matches(Paths.get("/Users/CSDSD/Desktop/bahar/bamboo/v1/latest/git/openssl/openssl/ms/applink.c"));
assertTrue(isMatches);

失败。这里有什么问题?

感谢

1 个答案:

答案 0 :(得分:1)

即使startingDir是一个空字符串,并且您在非Windows平台上运行,您也会像这样全局化:

glob:  /Users/CSDSD/Desktop/bahar/bamboo/v1/latest/git/openssl/openssl/**/ms/*.c
path:  /Users/CSDSD/Desktop/bahar/bamboo/v1/latest/git/openssl/openssl/ms/applink.c
  

**个字符匹配跨越目录边界的零个或多个字符。

但即使是零个字符,glob中也有2个/个字符,因此无法匹配路径中的单个/字符。

相关问题