From aed4b96a314c74b50e90a29e9da6149decd4ec48 Mon Sep 17 00:00:00 2001 From: agnostic-apollo Date: Fri, 22 Oct 2021 00:01:24 +0500 Subject: [PATCH] Added: Add FileUtils.regularOrDirectoryFileExists() --- .../java/com/termux/shared/file/FileUtils.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/termux-shared/src/main/java/com/termux/shared/file/FileUtils.java b/termux-shared/src/main/java/com/termux/shared/file/FileUtils.java index 0860c9ae..ee9bf9b3 100644 --- a/termux-shared/src/main/java/com/termux/shared/file/FileUtils.java +++ b/termux-shared/src/main/java/com/termux/shared/file/FileUtils.java @@ -220,6 +220,20 @@ public class FileUtils { return getFileType(filePath, false) == FileType.SYMLINK; } + /** + * Checks whether a regular or directory file exists at {@code filePath}. + * + * @param filePath The {@code path} for regular file to check. + * @param followLinks The {@code boolean} that decides if symlinks will be followed while + * finding if file exists. Check {@link #getFileType(String, boolean)} + * for details. + * @return Returns {@code true} if regular or directory file exists, otherwise {@code false}. + */ + public static boolean regularOrDirectoryFileExists(final String filePath, final boolean followLinks) { + FileType fileType = getFileType(filePath, followLinks); + return fileType == FileType.REGULAR || fileType == FileType.DIRECTORY; + } + /** * Checks whether any file exists at {@code filePath}. *