Package io.github.astrapi69.file.search
Class FileSearchExtensions
java.lang.Object
io.github.astrapi69.file.search.FileSearchExtensions
The class
FileSearchExtensions
provides methods for searching in directories.-
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
containsFile
(File parent, File search) Checks if the given file contains only in the parent file, not in the subdirectories.static boolean
containsFile
(File fileToSearch, String pathname) Checks if the given file contains in the parent file.static boolean
containsFileRecursive
(File parent, File search) Checks if the given file contains only in the parent file recursively.static long
countAllFilesInDirectory
(File dir, long length, boolean includeDirectories) Counts all the files in a directory recursively.findAllFiles
(File dir, String fileSearchPattern) Finds all files that match the search pattern.Finds all files that match the search pattern.List the directories from the given file(directory).findFiles
(File directory, Set<File> foundedDirs, FileFilter... excludeFileFilters) List the directories from the given file(directory).Searches for files with the given extensions and adds them to a Vector.findFilesRecursive
(File dir, boolean includeDir, String filenameToSearch) Finds all files that match the search pattern.findFilesRecursive
(File dir, String filenameToSearch) Finds all files that match the search pattern.findFilesRecursive
(File directory, Predicate<File> predicate) List the directories from the given file(directory).findFilesWithFilter
(File dir, String... extension) Finds all files that match the given extension.findFilesWithPrefixAndExtension
(File dir, String prefix, String extension) Finds all files in the specified directory that match the given prefix and file extension.findFilesWithPrefixAndExtensionRecursive
(File dir, String prefix, String extension) Finds all files recursively in the specified directory that match the given prefix and file extension.static int
findLineIndex
(File file, String searchString) Finds the index of the line in a File object that starts with the given stringgetAllFilesFromDir
(File dir) Gets the all files from directory.Gets all the files from directory recursive.getAllFilesFromDirRecursive
(File dir, boolean includeDir) Gets all the files from directory recursive.static long
Gets the file length from the given file in Kilobytes.static long
Gets the file length from the given file in Megabytes.static File
getRootDirectory
(File file) Gets the root directory from the givenFile
objectstatic String
getSearchFilePattern
(String... fileExtensions) Gets a regex search file pattern that can be used for searching files with a Matcher.List the directories from the given file(directory).static boolean
Checks the given String matches the given suffixes.
-
Method Details
-
getRootDirectory
Gets the root directory from the givenFile
object- Parameters:
file
- The file to search.- Returns:
- the root directory from the given
File
object
-
containsFile
Checks if the given file contains only in the parent file, not in the subdirectories.- Parameters:
parent
- The parent directory to search.search
- The file to search.- Returns:
- 's true if the file exists in the parent directory otherwise false.
-
containsFile
Checks if the given file contains in the parent file.- Parameters:
fileToSearch
- The parent directory to search.pathname
- The file to search.- Returns:
- 's true if the file exists in the parent directory otherwise false.
-
containsFileRecursive
Checks if the given file contains only in the parent file recursively.- Parameters:
parent
- The parent directory to search.search
- The file to search.- Returns:
- 's true if the file exists in the parent directory otherwise false.
-
findFiles
public static Set<File> findFiles(File directory, Set<File> foundedDirs, FileFilter... excludeFileFilters) List the directories from the given file(directory).- Parameters:
directory
- the directoryfoundedDirs
- the set with the founded directoriesexcludeFileFilters
- the file filters that have to be excluded- Returns:
- the
Set
with the found files
-
findFiles
List the directories from the given file(directory).- Parameters:
directory
- the directorypredicate
- the predicate- Returns:
- the
Set
with the found files - Throws:
IOException
- Signals that an I/O exception has occurred.
-
findFilesRecursive
public static Set<File> findFilesRecursive(File directory, Predicate<File> predicate) throws IOException List the directories from the given file(directory).- Parameters:
directory
- the directorypredicate
- the predicate- Returns:
- the
Set
with the found files - Throws:
IOException
- Signals that an I/O exception has occurred.
-
countAllFilesInDirectory
Counts all the files in a directory recursively. This includes files in the subdirectories.- Parameters:
dir
- the directory.length
- the current length. By start is this 0.includeDirectories
- If this is true then the directories are in the count too.- Returns:
- the total number of files.
-
findAllFiles
Finds all files that match the search pattern. The search is not recursively.- Parameters:
dir
- The directory to search.fileSearchPattern
- The regex file search pattern.- Returns:
- A List with all files that matches the search pattern.
-
findFiles
Finds all files that match the search pattern. The search is not recursively.- Parameters:
dir
- The directory to search.filenameToSearch
- The search pattern. Allowed wildcards are "*" and "?".- Returns:
- A List with all files that matches the search pattern.
-
findFiles
Searches for files with the given extensions and adds them to a Vector.- Parameters:
start
- The path to the file.extensions
- The extensions to find.- Returns:
- Returns a Vector all founded files.
-
findFilesRecursive
Finds all files that match the search pattern. The search is recursively.- Parameters:
dir
- The directory to search.filenameToSearch
- The search pattern. Allowed wildcards are "*" and "?".- Returns:
- A List with all files that matches the search pattern.
-
findFilesRecursive
Finds all files that match the search pattern. The search is recursively.- Parameters:
dir
- The directory to search.includeDir
- The flag that tells if the directory files should be added to the returned listfilenameToSearch
- The search pattern. Allowed wildcards are "*" and "?".- Returns:
- A List with all files that matches the search pattern.
-
findFilesWithFilter
Finds all files that match the given extension. The search is recursively.- Parameters:
dir
- The directory to search.extension
- The extensions to search.- Returns:
- A List with all files that matches the search pattern.
-
findLineIndex
Finds the index of the line in a File object that starts with the given string- Parameters:
file
- the File object to searchsearchString
- the string to search for- Returns:
- the index of the line that contains the string, or -1 if not found
- Throws:
IOException
- if an I/O error occurs
-
getAllFilesFromDir
Gets the all files from directory.- Parameters:
dir
- the dir- Returns:
- A list with all files from the given directory.
-
getAllFilesFromDirRecursive
Gets all the files from directory recursive.- Parameters:
dir
- the directory- Returns:
- the all files from dir recursive
-
getAllFilesFromDirRecursive
Gets all the files from directory recursive.- Parameters:
dir
- the directoryincludeDir
- The flag that tells if the directory files should be added to the returned list- Returns:
- the all files from dir recursive
-
getFileLengthInKilobytes
Gets the file length from the given file in Kilobytes.- Parameters:
dir
- the dir- Returns:
- Returns the file length from the given file in Kilobytes.
-
getFileLengthInMegabytes
Gets the file length from the given file in Megabytes.- Parameters:
dir
- the directory- Returns:
- Returns the file length from the given file in Megabytes.
-
getSearchFilePattern
Gets a regex search file pattern that can be used for searching files with a Matcher.- Parameters:
fileExtensions
- The file extensions that shell exist in the search pattern.- Returns:
- a regex search file pattern that can be used for searching files with a Matcher.
-
listDirs
List the directories from the given file(directory).- Parameters:
dir
- the directory.- Returns:
- the list
-
match
Checks the given String matches the given suffixes.- Parameters:
stringToMatch
- The string to compare.suffixes
- An array with suffixes.- Returns:
- Returns true if matches otherwise false.
-
findFilesWithPrefixAndExtension
Finds all files in the specified directory that match the given prefix and file extension.- Parameters:
dir
- The directory in which to search for files.prefix
- The prefix that the filenames should start with.extension
- The file extension that the filenames should have.- Returns:
- A list of files that match the specified prefix and extension.
-
findFilesWithPrefixAndExtensionRecursive
public static List<File> findFilesWithPrefixAndExtensionRecursive(File dir, String prefix, String extension) Finds all files recursively in the specified directory that match the given prefix and file extension.- Parameters:
dir
- The directory in which to search for files.prefix
- The prefix that the filenames should start with.extension
- The file extension that the filenames should have.- Returns:
- A list of files that match the specified prefix and extension.
-