あなたはPathMatcherを使用してwildcardardを使用することができます。
あなたのPathMatcherのために、このようなパターンを使用することができます。
/* Find test.zip in any subfolder inside 'origin + folderNames.get(i)'
* If origin + folderNames.get(i) is \test\orig\test_1
* The pattern will match:
* \test\orig\test_1\randomfolder\test.zip
* But won't match (Use ** instead of * to match these Paths):
* \test\orig\test_1\randomfolder\anotherRandomFolder\test.zip
* \test\orig\test_1\test.zip
*/
String pattern = origin + folderNames.get(i) + "/*/test.zip";
ありますFileSysten.getPathMatherメソッドのこのパターンの構文に関する詳細。 PathMatherを作成するコードは次のようになります。
PathMatcher pathMatcher = FileSystems.getDefault().getPathMatcher("glob:" + pattern);
あなたはFiles.find()
メソッドを使用してこのパターンに一致するすべてのファイルを見つけることができます:
Stream<Path> paths = Files.find(basePath, Integer.MAX_VALUE, (path, f)->pathMatcher.matches(path));
findメソッドはStream<Path>
を返します。そのストリームに対して操作を実行したり、リストに変換することができます。
paths.forEach(...);
または:
List<Path> pathsList = paths.collect(Collectors.toList());
あなたはより深い1つのフォルダを何を意味するか、あなたが行きたいフォルダいる指定する必要があります。 –
試しましたか?http://stackoverflow.com/questions/30088245/java-7-nio-list-directory-with-wildcard – kjsebastian
明快に試して編集します – Warweedy