EventAnalysis  1.3.0
Static Public Member Functions | List of all members
EA::FileUtils Class Reference

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...
 

Detailed Description

A static class with file utility functions.

Member Function Documentation

◆ FindFile()

template<class Container >
std::string EA::FileUtils::FindFile ( const std::string &  fileName,
const Container &  folders,
bool  cwd = false 
)
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.

Parameters
fileNameThe name of the file (possibly an absolute or relative path).
foldersThe list of folders where the file will be searched.
cwdIf true, the file will be searched also in the current working directory.
Returns
a string with the full path to the found file; an empty string if the file is not found.

◆ GetCWD()

std::string EA::FileUtils::GetCWD ( )
static

Get the current working directory.

Returns
A string containing the name of the current working directory.

◆ Glob()

template<template< class, class > class Container>
Container< std::string, std::allocator< std::string > > EA::FileUtils::Glob ( const std::string &  pattern)
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

Parameters
patternThe glob expression to be matched.
Returns
All the file names matching the given pattern.

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