From 95a16abec29f44e79d8174efb7afeb60057b20ea Mon Sep 17 00:00:00 2001 From: Jonathan Cobb Date: Sun, 15 Nov 2020 05:52:37 -0500 Subject: [PATCH] add findFile to find a file with a specific name --- .../java/org/cobbzilla/util/io/FileUtil.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/main/java/org/cobbzilla/util/io/FileUtil.java b/src/main/java/org/cobbzilla/util/io/FileUtil.java index 05e26b8..ae98361 100644 --- a/src/main/java/org/cobbzilla/util/io/FileUtil.java +++ b/src/main/java/org/cobbzilla/util/io/FileUtil.java @@ -608,4 +608,20 @@ public class FileUtil { }).walk(); return found.get(); } + + public static File findFile(File dir, String name) { + final AtomicReference found = new AtomicReference<>(null); + new FilesystemWalker() + .withDir(dir) + .withVisitor(file -> { + if (found.get() != null) return; + if (file.getName().equals(name)) { + synchronized (found) { + if (found.get() == null) found.set(file); + } + } + }).walk(); + return found.get(); + } + }