Interface Searchable
public interface Searchable
Interface for searching capabilities within files and directories
-
Method Summary
Modifier and TypeMethodDescriptiondefault boolean
containsFile
(File parent, File search) Checks if the parent directory contains the specified file by filenamedefault boolean
containsFile
(File parent, String pathname) Checks if the parent directory contains a file matching the specified filenamedefault long
countAllFilesInDirectory
(File dir, long length, boolean includeDirectories) Counts all files in a directory recursively, optionally including directories in the countfindAllFiles
(File dir, String fileSearchPattern) Finds files within a directory matching a specified search pattern (regex)Searches for files in a directory matching a specified predicateFinds all files in a directory with the specified extensionsfindFilesRecursive
(File directory, Predicate<File> predicate) Recursively searches for files in a directory matching a specified predicatefindFilesWithPrefixAndExtensionRecursive
(File dir, String prefix, String extension) Finds all files in the specified directory and subdirectories that match the given prefix and extensiongetAllFilesFromDir
(File dir) Retrieves all files from a directoryRetrieves all files from a directory recursivelydefault File
getRootDirectory
(File file) Retrieves the root directory of the given file object
-
Method Details
-
getRootDirectory
Retrieves the root directory of the given file object- Parameters:
file
- the file to analyze- Returns:
- the root directory from the given file
-
containsFile
Checks if the parent directory contains the specified file by filename- Parameters:
parent
- the directory to search withinsearch
- the file to locate- Returns:
- true if the file exists in the parent directory otherwise false
-
containsFile
Checks if the parent directory contains a file matching the specified filename- Parameters:
parent
- the directory to search withinpathname
- the filename to search for- Returns:
- true if the file exists in the parent directory otherwise false
-
findFiles
Searches for files in a directory matching a specified predicate- Parameters:
directory
- the directory to searchpredicate
- the condition to filter files- Returns:
- a set of files that match the predicate
- Throws:
IOException
- if an I/O error occurs
-
findFilesRecursive
Recursively searches for files in a directory matching a specified predicate- Parameters:
directory
- the directory to searchpredicate
- the condition to filter files- Returns:
- a set of files that match the predicate
- Throws:
IOException
- if an I/O error occurs
-
countAllFilesInDirectory
Counts all files in a directory recursively, optionally including directories in the count- Parameters:
dir
- the directory to count files inlength
- the starting countincludeDirectories
- flag to include directories in the count if true- Returns:
- the total number of files and directories
-
findAllFiles
Finds files within a directory matching a specified search pattern (regex)- Parameters:
dir
- the directory to searchfileSearchPattern
- the regex pattern to match filenames against- Returns:
- a list of matching files
-
findFiles
Finds all files in a directory with the specified extensions- Parameters:
start
- the starting directoryextensions
- array of file extensions to search for- Returns:
- a list of files that match the specified extensions
-
getAllFilesFromDir
Retrieves all files from a directory- Parameters:
dir
- the directory to retrieve files from- Returns:
- a list of files in the directory
-
getAllFilesFromDirRecursive
Retrieves all files from a directory recursively- Parameters:
dir
- the directory to retrieve files from- Returns:
- a list of all files in the directory and its subdirectories
-
findFilesWithPrefixAndExtensionRecursive
default List<File> findFilesWithPrefixAndExtensionRecursive(File dir, String prefix, String extension) Finds all files in the specified directory and subdirectories that match the given prefix and extension- Parameters:
dir
- the directory in which to search for filesprefix
- the prefix that filenames should start withextension
- the file extension that filenames should have- Returns:
- a list of files that match the specified prefix and extension
-