Function utils::getFilePath
Defined in File MiscUtils.hpp
Function Documentation
-
inline auto utils::getFilePath(const std::string &fileName, const std::string &prefix = "")
Look for a file in the current working directory, SLUG_DIR, SLUG_DATA_PATH, or REPO_DIR.
This routine searches for files with the name fileName in the current working directory, the directory specified by the environment variable SLUG_DIR, each directory listed in the environment variable SLUG_DATA_PATH, and REPO_DIR (the directory containing the project’s top-level CMakeLists.txt, baked in at compile time – see CMakeLists.txt), with the following resolution rules: (1) If a file matching fileName exists in the current working directory, return the path to it. (2) If a matching file is not found and fileName specifies an absolute path, return an empty path. (3) If fileName is not an absolute path, and the environment variable SLUG_DIR is set, search for a file named SLUG_DIR/prefix/fileName, and return a path to it if found. (4) If still not found, and the environment variable SLUG_DATA_PATH is set, treat it as a list of directories separated as in PATH (see splitSearchPath), and search each one, in order, for a file named dir/prefix/fileName, returning a path to the first one found. slugpy sets this (see slugpy/_paths.py) so that a pip-installed copy of slug can find both its own bundled data files and any large data downloaded into a per-user data directory. (5) If still not found, and REPO_DIR is not empty, search for a file named REPO_DIR/prefix/fileName, and return a path to it if found. REPO_DIR is empty for a pip-installed build, whose source tree does not outlive installation. (6) Otherwise, return an empty path.
- Parameters:
fileName – File name
prefix – Prefix within SLUG_DIR/SLUG_DATA_PATH/REPO_DIR to search
- Returns:
Path to file