JUCE: FileSearchPath Class Reference

JUCE

- Main Page
- Related Pages
- Topics
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

Loading...
Searching...
No Matches
Public Member Functions | List of all members
FileSearchPath Class Reference
juce_core » files

Represents a set of folders that make up a search path. More...

`#include <juce_FileSearchPath.h>`

## Public Member Functions
| FileSearchPath ()=default
| Creates an empty search path.
| ~FileSearchPath ()=default
| Destructor.
| FileSearchPath (const String &path)
| Creates a search path from a string of pathnames.
| FileSearchPath (const FileSearchPath &)
| Creates a copy of another search path.
FileSearchPath & | operator= (const FileSearchPath &)
| Copies another search path.
FileSearchPath & | operator= (const String &path)
| Uses a string containing a list of pathnames to re-initialise this list.
int | getNumPaths () const
| Returns the number of folders in this search path.
File | operator[] (int index) const
| Returns one of the folders in this search path.
String | getRawString (int index) const
| Returns the unaltered text of the folder at the specified index.
String | toString () const
| Returns the search path as a semicolon-separated list of directories.
String | toStringWithSeparator (StringRef separator) const
| Returns the search paths, joined with the provided separator.
void | add (const File &directoryToAdd, int insertIndex=-1)
| Adds a new directory to the search path.
bool | addIfNotAlreadyThere (const File &directoryToAdd)
| Adds a new directory to the search path if it's not already in there.
void | remove (int indexToRemove)
| Removes a directory from the search path.
void | addPath (const FileSearchPath &)
| Merges another search path into this one.
void | removeRedundantPaths ()
| Removes any directories that are actually subdirectories of one of the other directories in the search path.
void | removeNonExistentPaths ()
| Removes any directories that don't actually exist.
Array< File > | findChildFiles (int whatToLookFor, bool searchRecursively, const String &wildCardPattern="*") const
| Searches the path for a wildcard.
int | findChildFiles (Array< File > &results, int whatToLookFor, bool searchRecursively, const String &wildCardPattern="*") const
| Searches the path for a wildcard.
bool | isFileInPath (const File &fileToCheck, bool checkRecursively) const
| Finds out whether a file is inside one of the path's directories.

## Detailed Description

Represents a set of folders that make up a search path.

See also
  File

## Constructor & Destructor Documentation

## ◆ FileSearchPath() [1/3]

FileSearchPath::FileSearchPath | ( |  | ) |
| default

Creates an empty search path.

## ◆ ~FileSearchPath()

FileSearchPath::~FileSearchPath | ( |  | ) |
| default

Destructor.

## ◆ FileSearchPath() [2/3]

FileSearchPath::FileSearchPath | ( | const String & | path | ) |

Creates a search path from a string of pathnames.

The path can be semicolon- or comma-separated, e.g. "/foo/bar;/foo/moose;/fish/moose"

The separate folders are tokenised and added to the search path.

## ◆ FileSearchPath() [3/3]

FileSearchPath::FileSearchPath | ( | const FileSearchPath & |  | ) |

Creates a copy of another search path.

## Member Function Documentation

## ◆ operator=() [1/2]

FileSearchPath & FileSearchPath::operator= | ( | const FileSearchPath & |  | ) |

Copies another search path.

## ◆ operator=() [2/2]

FileSearchPath & FileSearchPath::operator= | ( | const String & | path | ) |

Uses a string containing a list of pathnames to re-initialise this list.

This search path is cleared and the semicolon- or comma-separated folders in this string are added instead. e.g. "/foo/bar;/foo/moose;/fish/moose"

## ◆ getNumPaths()

int FileSearchPath::getNumPaths | ( |  | ) | const

Returns the number of folders in this search path.

See also
  operator[]

## ◆ operator[]()

File FileSearchPath::operator[] | ( | int | index | ) | const

Returns one of the folders in this search path.

The file returned isn't guaranteed to actually be a valid directory.

See also
  getNumPaths, getRawString

## ◆ getRawString()

String FileSearchPath::getRawString | ( | int | index | ) | const

Returns the unaltered text of the folder at the specified index.

Unlike operator[], this function returns the exact text that was entered. It does not attempt to convert the path into an absolute path.

This may be useful if the directory string is expected to understand environment variables or other placeholders that the File constructor doesn't necessarily understand.

See also
  operator[]

## ◆ toString()

String FileSearchPath::toString | ( |  | ) | const

Returns the search path as a semicolon-separated list of directories.

## ◆ toStringWithSeparator()

String FileSearchPath::toStringWithSeparator | ( | StringRef | separator | ) | const

Returns the search paths, joined with the provided separator.

## ◆ add()

void FileSearchPath::add | ( | const File & | directoryToAdd,
|  | int | insertIndex = -1 )

Adds a new directory to the search path.

The new directory is added to the end of the list if the insertIndex parameter is less than zero, otherwise it is inserted at the given index.

## ◆ addIfNotAlreadyThere()

bool FileSearchPath::addIfNotAlreadyThere | ( | const File & | directoryToAdd | ) |

Adds a new directory to the search path if it's not already in there.

Returns
  true if the directory has been added, false otherwise.

## ◆ remove()

void FileSearchPath::remove | ( | int | indexToRemove | ) |

Removes a directory from the search path.

## ◆ addPath()

void FileSearchPath::addPath | ( | const FileSearchPath & |  | ) |

Merges another search path into this one.

This will remove any duplicate directories.

## ◆ removeRedundantPaths()

void FileSearchPath::removeRedundantPaths | ( |  | ) |

Removes any directories that are actually subdirectories of one of the other directories in the search path.

If the search is intended to be recursive, there's no point having nested folders in the search path, because they'll just get searched twice and you'll get duplicate results.

e.g. if the path is "c:\abc\de;c:\abc", this method will simplify it to "c:\abc"

## ◆ removeNonExistentPaths()

void FileSearchPath::removeNonExistentPaths | ( |  | ) |

Removes any directories that don't actually exist.

## ◆ findChildFiles() [1/2]

Array< File > FileSearchPath::findChildFiles | ( | int | whatToLookFor,
|  | bool | searchRecursively,
|  | const String & | wildCardPattern = "*" ) const

Searches the path for a wildcard.

This will search all the directories in the search path in order and return an array of the files that were found.

Parameters

  whatToLookFor | a value from the File::TypesOfFileToFind enum, specifying whether to return files, directories, or both.
  searchRecursively | whether to recursively search the subdirectories too
  wildCardPattern | a pattern to match against the filenames

Returns
  the number of files added to the array

See also
  File::findChildFiles

## ◆ findChildFiles() [2/2]

int FileSearchPath::findChildFiles | ( | Array< File > & | results,
|  | int | whatToLookFor,
|  | bool | searchRecursively,
|  | const String & | wildCardPattern = "*" ) const

Searches the path for a wildcard.

Note that there's a newer, better version of this method which returns the results array, and in almost all cases, you should use that one instead! This one is kept around mainly for legacy code to use.

## ◆ isFileInPath()

bool FileSearchPath::isFileInPath | ( | const File & | fileToCheck,
|  | bool | checkRecursively ) const

Finds out whether a file is inside one of the path's directories.

This will return true if the specified file is a child of one of the directories specified by this path. Note that this doesn't actually do any searching or check that the files exist - it just looks at the pathnames to work out whether the file would be inside a directory.

Parameters

  fileToCheck | the file to look for
  checkRecursively | if true, then this will return true if the file is inside a subfolder of one of the path's directories (at any depth). If false it will only return true if the file is actually a direct child of one of the directories.

See also
  File::isAChildOf

The documentation for this class was generated from the following file:

- juce_FileSearchPath.h