MeteoIODoc 2.11.0
mio::FileUtils Namespace Reference

Classes

class  FileIndexer
 

Functions

void readDirectoryPrivate (const std::string &path, const std::string &sub_path, std::list< std::string > &dirlist, const std::string &pattern="", const bool &isRecursive=false)
 
void copy_file (const std::string &src, const std::string &dest)
 Copies a files from one location to another. More...
 
std::string cleanPath (std::string in_path, const bool &resolve=false, const bool &silent=false)
 Replace "\" by "/" in a string so that a path string is cross plateform, optionally resolve links, convert relative paths to absolute paths, etc. More...
 
std::string getExtension (const std::string &filename)
 returns the extension part of a given filename. More...
 
std::string removeExtension (const std::string &filename)
 remove the extension part of a given filename. More...
 
std::string getPath (const std::string &filename, const bool &resolve=false)
 returns the path preceeding a given filename. More...
 
std::string getFilename (const std::string &path)
 extract the file name from a path+filename string. More...
 
std::string getDateTime ()
 returns the current date and time as a string. More...
 
bool validFileAndPath (const std::string &filename)
 
bool isAbsolutePath (const std::string &in_path)
 checks if a path is an absolute path More...
 
void readDirectory (const std::string &path, std::list< std::string > &dirlist, const std::string &pattern="", const bool &isRecursive=false)
 Build a list of file in a given directory. More...
 
std::list< std::string > readDirectory (const std::string &path, const std::string &pattern, const bool &isRecursive)
 
bool directoryExists (const std::string &path)
 
bool isWindowsPath (const std::string &path)
 
void createDirectories (const std::string &path)
 creates the directory tree for the given path, including missing intermediate directories (gives only rw permissions), only takes paths delimited with '/' More...
 
std::string getCWD ()
 returns the current working directory. More...
 
bool fileExists (const std::string &filename)
 
char getEoln (std::istream &fin)
 
void skipLines (std::istream &fin, const size_t &nbLines, const char &eoln)
 
std::map< std::string, std::string > readKeyValueHeader (std::istream &fin, const size_t &linecount, const std::string &delimiter, const bool &keep_case)
 

Function Documentation

◆ cleanPath()

std::string mio::FileUtils::cleanPath ( std::string  in_path,
const bool &  resolve = false,
const bool &  silent = false 
)

Replace "\" by "/" in a string so that a path string is cross plateform, optionally resolve links, convert relative paths to absolute paths, etc.

Parameters
in_paththe path string to cleanup
resolveresolve links, convert relative paths, etc? (default=false)
silentdo not print error messages if set to true (only useful to send another error message later)

◆ copy_file()

void mio::FileUtils::copy_file ( const std::string &  src,
const std::string &  dest 
)

Copies a files from one location to another.

Author
Thomas Egger
Parameters
srcThe filename of the file to be copied
destThe filename of the file to copy to (will be created or overwritten)

◆ createDirectories()

void mio::FileUtils::createDirectories ( const std::string &  path)

creates the directory tree for the given path, including missing intermediate directories (gives only rw permissions), only takes paths delimited with '/'

Parameters
pathdirectory tree to create, cannot include filenames

◆ directoryExists()

bool mio::FileUtils::directoryExists ( const std::string &  path)

◆ fileExists()

bool mio::FileUtils::fileExists ( const std::string &  filename)

◆ getCWD()

std::string mio::FileUtils::getCWD ( )

returns the current working directory.

Returns
path

◆ getDateTime()

std::string mio::FileUtils::getDateTime ( )

returns the current date and time as a string.

Returns
date and time

◆ getEoln()

char mio::FileUtils::getEoln ( std::istream &  fin)

◆ getExtension()

std::string mio::FileUtils::getExtension ( const std::string &  filename)

returns the extension part of a given filename.

The extension is defined as all the non-whitespace characters after the last '.' in the filename.

Parameters
filenamefilename to extract the extension from
Returns
extension

◆ getFilename()

std::string mio::FileUtils::getFilename ( const std::string &  path)

extract the file name from a path+filename string.

Parameters
pathpath to extract the true filename from
Returns
filename

◆ getPath()

std::string mio::FileUtils::getPath ( const std::string &  filename,
const bool &  resolve = false 
)

returns the path preceeding a given filename.

Parameters
filenamefilename to extract the path from
resolveresolve links, convert relative paths, etc? (default=false)
Returns
path

◆ isAbsolutePath()

bool mio::FileUtils::isAbsolutePath ( const std::string &  in_path)

checks if a path is an absolute path

Parameters
in_pathstring containing the path to check
Returns
true if the given string represents an absolute path

◆ isWindowsPath()

bool mio::FileUtils::isWindowsPath ( const std::string &  path)

◆ readDirectory() [1/2]

std::list< std::string > mio::FileUtils::readDirectory ( const std::string &  path,
const std::string &  pattern,
const bool &  isRecursive 
)

◆ readDirectory() [2/2]

void mio::FileUtils::readDirectory ( const std::string &  path,
std::list< std::string > &  dirlist,
const std::string &  pattern = "",
const bool &  isRecursive = false 
)

Build a list of file in a given directory.

The matching is very primitive: it only looks for the substring "pattern" in the file names. If this substrings exists, the file matches. In the case of recursive search, the filenames will be prefixed by their relative path based on the provided path.

Note
Hidden files/directories are excluded, links are followed
Parameters
pathdirectory containing the files
dirlistlist of matching file names
patternoptional pattern that must be part of the file names
isRecursiveshould the search recurse through sub-directories? (default: false)

◆ readDirectoryPrivate()

void mio::FileUtils::readDirectoryPrivate ( const std::string &  path,
const std::string &  sub_path,
std::list< std::string > &  dirlist,
const std::string &  pattern = "",
const bool &  isRecursive = false 
)

◆ readKeyValueHeader()

std::map< std::string, std::string > mio::FileUtils::readKeyValueHeader ( std::istream &  fin,
const size_t &  linecount,
const std::string &  delimiter,
const bool &  keep_case 
)

◆ removeExtension()

std::string mio::FileUtils::removeExtension ( const std::string &  filename)

remove the extension part of a given filename.

The extension is defined as all the non-whitespace characters after the last '.' in the filename.

Parameters
filenamefilename to remove the extension from
Returns
filename without extension (the '.' is also removed)

◆ skipLines()

void mio::FileUtils::skipLines ( std::istream &  fin,
const size_t &  nbLines,
const char &  eoln 
)

◆ validFileAndPath()

bool mio::FileUtils::validFileAndPath ( const std::string &  filename)