EventAnalysis
1.3.0
|
A static class with file utility functions. More...
#include <FileUtils.h>
Static Public Member Functions | |
template<class Container > | |
static std::string | FindFile (const std::string &fileName, const Container &folders, bool cwd=false) |
Search for the given file inside the given folders. More... | |
static std::string | GetCWD () |
Get the current working directory. More... | |
template<template< class, class > class Container = std::vector> | |
static Container< std::string, std::allocator< std::string > > | Glob (const std::string &pattern) |
Find all files matching a pattern. More... | |
A static class with file utility functions.
|
static |
Search for the given file inside the given folders.
This method searches for a file inside a list of folders. The file name is concatenated to each folder and the existence is then checked, so #fileName can also be a relative path. If #cwd is set to true then the file will be searched also relatively to the current working directory. If #fileName is an absolute path then #folders and #cwd will be ignored. The return value is the full path of the file, or an empty string if the file has not been found.
fileName | The name of the file (possibly an absolute or relative path). |
folders | The list of folders where the file will be searched. |
cwd | If true, the file will be searched also in the current working directory. |
|
static |
Get the current working directory.
|
static |
Find all files matching a pattern.
This function returns all the file names matching the input pattern. The return value is by default a std::vector<std::string>. If another type of container for the return strings is desired then it can be specified in the function call. For example:
auto filesVect = FileUtils::Glob(pattern); // Returns a std::vector<std::string> auto filesList = FileUtils::Glob<std::list>(pattern); // Returns a std::list<std::string>
Adapted from:
https://stackoverflow.com/questions/8401777/simple-glob-in-c-on-unix-system
pattern | The glob expression to be matched. |