Package io.github.astrapi69.file.search
Class FileSearchExtensions
- java.lang.Object
-
- io.github.astrapi69.file.search.FileSearchExtensions
-
public final class FileSearchExtensions extends java.lang.Object
The classFileSearchExtensions
provides methods for searching in directories.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static boolean
containsFile(java.io.File parent, java.io.File search)
Checks if the given file contains only in the parent file, not in the subdirectories.static boolean
containsFile(java.io.File fileToSearch, java.lang.String pathname)
Checks if the given file contains in the parent file.static boolean
containsFileRecursive(java.io.File parent, java.io.File search)
Checks if the given file contains only in the parent file recursively.static long
countAllFilesInDirectory(java.io.File dir, long length, boolean includeDirectories)
Counts all the files in a directory recursively.static java.util.List<java.io.File>
findAllFiles(java.io.File dir, java.lang.String fileSearchPattern)
Finds all files that match the search pattern.static java.util.List<java.io.File>
findFiles(java.io.File dir, java.lang.String filenameToSearch)
Finds all files that match the search pattern.static java.util.Set<java.io.File>
findFiles(java.io.File directory, java.util.function.Predicate<java.io.File> predicate)
List the directories from the given file(directory).static java.util.Set<java.io.File>
findFiles(java.io.File directory, java.util.Set<java.io.File> foundedDirs, java.io.FileFilter... excludeFileFilters)
List the directories from the given file(directory).static java.util.List<java.io.File>
findFiles(java.lang.String start, java.lang.String[] extensions)
Searches for files with the given extensions and adds them to a Vector.static java.util.List<java.io.File>
findFilesRecursive(java.io.File dir, java.lang.String filenameToSearch)
Finds all files that match the search pattern.static java.util.Set<java.io.File>
findFilesRecursive(java.io.File directory, java.util.function.Predicate<java.io.File> predicate)
List the directories from the given file(directory).static java.util.List<java.io.File>
findFilesWithFilter(java.io.File dir, java.lang.String... extension)
Finds all files that match the given extension.static java.util.List<java.io.File>
getAllFilesFromDir(java.io.File dir)
Gets the all files from directory.static java.util.List<java.io.File>
getAllFilesFromDirRecursive(java.io.File dir)
Gets all the files from directory recursive.static long
getFileLengthInKilobytes(java.io.File dir)
Gets the file length from the given file in Kilobytes.static long
getFileLengthInMegabytes(java.io.File dir)
Gets the file length from the given file in Megabytes.static java.io.File
getRootDirectory(java.io.File file)
Gets the root directory from the givenFile
objectstatic java.lang.String
getSearchFilePattern(java.lang.String... fileExtensions)
Gets a regex search file pattern that can be used for searching files with a Matcher.static java.util.List<java.io.File>
listDirs(java.io.File dir)
List the directories from the given file(directory).static boolean
match(java.lang.String stringToMatch, java.lang.String[] suffixes)
Checks the given String matches the given suffixes.
-
-
-
Method Detail
-
getRootDirectory
public static java.io.File getRootDirectory(java.io.File file)
Gets the root directory from the givenFile
object- Parameters:
file
- The file to search.- Returns:
- the root directory from the given
File
object
-
containsFile
public static boolean containsFile(java.io.File parent, java.io.File search)
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
public static boolean containsFile(java.io.File fileToSearch, java.lang.String pathname)
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
public static boolean containsFileRecursive(java.io.File parent, java.io.File search)
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 java.util.Set<java.io.File> findFiles(java.io.File directory, java.util.Set<java.io.File> foundedDirs, java.io.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
public static java.util.Set<java.io.File> findFiles(java.io.File directory, java.util.function.Predicate<java.io.File> predicate) throws java.io.IOException
List the directories from the given file(directory).- Parameters:
directory
- the directorypredicate
- the predicate- Returns:
- the
Set
with the found files - Throws:
java.io.IOException
- Signals that an I/O exception has occurred.
-
findFilesRecursive
public static java.util.Set<java.io.File> findFilesRecursive(java.io.File directory, java.util.function.Predicate<java.io.File> predicate) throws java.io.IOException
List the directories from the given file(directory).- Parameters:
directory
- the directorypredicate
- the predicate- Returns:
- the
Set
with the found files - Throws:
java.io.IOException
- Signals that an I/O exception has occurred.
-
countAllFilesInDirectory
public static long countAllFilesInDirectory(java.io.File dir, long length, boolean includeDirectories)
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
public static java.util.List<java.io.File> findAllFiles(java.io.File dir, java.lang.String fileSearchPattern)
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
public static java.util.List<java.io.File> findFiles(java.io.File dir, java.lang.String filenameToSearch)
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
public static java.util.List<java.io.File> findFiles(java.lang.String start, java.lang.String[] extensions)
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
public static java.util.List<java.io.File> findFilesRecursive(java.io.File dir, java.lang.String filenameToSearch)
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.
-
findFilesWithFilter
public static java.util.List<java.io.File> findFilesWithFilter(java.io.File dir, java.lang.String... extension)
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.
-
getAllFilesFromDir
public static java.util.List<java.io.File> getAllFilesFromDir(java.io.File dir)
Gets the all files from directory.- Parameters:
dir
- the dir- Returns:
- A list with all files from the given directory.
-
getAllFilesFromDirRecursive
public static java.util.List<java.io.File> getAllFilesFromDirRecursive(java.io.File dir)
Gets all the files from directory recursive.- Parameters:
dir
- the directory- Returns:
- the all files from dir recursive
-
getFileLengthInKilobytes
public static long getFileLengthInKilobytes(java.io.File dir)
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
public static long getFileLengthInMegabytes(java.io.File dir)
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
public static java.lang.String getSearchFilePattern(java.lang.String... fileExtensions)
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
public static java.util.List<java.io.File> listDirs(java.io.File dir)
List the directories from the given file(directory).- Parameters:
dir
- the directory.- Returns:
- the list
-
match
public static boolean match(java.lang.String stringToMatch, java.lang.String[] suffixes)
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.
-
-