bpp-core3  3.0.0
bpp::FileTools Class Reference

Some utilitary functions to deal with files. More...

#include <Bpp/Io/FileTools.h>

Public Member Functions

 FileTools ()
 
virtual ~FileTools ()
 

Static Public Member Functions

static bool fileExists (const std::string &filename)
 Tells if a file exist. More...
 
static bool directoryExists (const std::string &path)
 Tells if a directory exist. More...
 
static std::string getFileName (const std::string &path, char dirSep=DIR_SEP)
 Get the name of of a file, without extension. More...
 
static std::streampos getFileSize (const std::string &filename)
 Get the size of a file. More...
 
static std::string getParent (const std::string &path, char dirSep=DIR_SEP)
 Get the path of the parent directry of the given file/dir. More...
 
static std::string getExtension (const std::string &path)
 Get the extension of a file. More...
 
static std::vector< std::string > putStreamIntoVectorOfStrings (std::istream &input)
 Reads a stream and write each line in a vector. More...
 
static std::string getNextLine (std::istream &in)
 Get the next non-blanck line of a stream. More...
 

Static Public Attributes

static char DIR_SEP = '/'
 

Detailed Description

Some utilitary functions to deal with files.

File paths default to unix, i.e. the directory seprator if '/'. This character is stored in the variable 'DIR_SEP', and hence may be changed by

for windows programs.

Methods dealing with pathes have an optional dirSep argument, which default to DIR_SEP.

Definition at line 31 of file FileTools.h.

Constructor & Destructor Documentation

◆ FileTools()

bpp::FileTools::FileTools ( )
inline

Definition at line 37 of file FileTools.h.

◆ ~FileTools()

virtual bpp::FileTools::~FileTools ( )
inlinevirtual

Member Function Documentation

◆ directoryExists()

bool FileTools::directoryExists ( const std::string &  path)
static

Tells if a directory exist.

NB: this is an alias for fileExists.

Parameters
pathThe path toward the file.
Returns
True if the file exists.

Definition at line 29 of file FileTools.cpp.

Referenced by ~FileTools().

◆ fileExists()

bool FileTools::fileExists ( const std::string &  filename)
static

Tells if a file exist.

Parameters
filenameThe path toward the file.
Returns
True if the file exists.

Definition at line 19 of file FileTools.cpp.

Referenced by bpp::ApplicationTools::getAFilePath(), and ~FileTools().

◆ getExtension()

std::string FileTools::getExtension ( const std::string &  path)
static

Get the extension of a file.

Example: FileTools::getExtension("/path/file.ext") returns "ext". This method is not recursive, hence FileTools::getExtension("/home/me/archive.tar.gz") returns "gz".

Parameters
pathA file path.
Returns
The extension of the file specified by path.

Definition at line 86 of file FileTools.cpp.

Referenced by ~FileTools().

◆ getFileName()

std::string FileTools::getFileName ( const std::string &  path,
char  dirSep = DIR_SEP 
)
static

Get the name of of a file, without extension.

Example: FileTools::getFileName("/path/file.ext") returns "file". This method is not recursive, hence FileTools::getfileName("/home/me/archive.tar.gz") returns "archive".

An empty string is returned if 'path' is not a valid path toward a file.

Parameters
pathA file path.
dirSepThe directory separator.
Returns
The filename of the file specified by path.

Definition at line 39 of file FileTools.cpp.

Referenced by ~FileTools().

◆ getFileSize()

streampos FileTools::getFileSize ( const std::string &  filename)
static

Get the size of a file.

Parameters
filenameThe path toward the file.
Returns
The size of the file.
Author
Sylvain Gaillard

Definition at line 59 of file FileTools.cpp.

Referenced by ~FileTools().

◆ getNextLine()

std::string FileTools::getNextLine ( std::istream &  in)
static

Get the next non-blanck line of a stream.

Parameters
inInput stream.

Definition at line 108 of file FileTools.cpp.

References bpp::TextTools::isEmpty().

Referenced by bpp::DataTable::read(), bpp::Table< T >::read(), and ~FileTools().

◆ getParent()

std::string FileTools::getParent ( const std::string &  path,
char  dirSep = DIR_SEP 
)
static

Get the path of the parent directry of the given file/dir.

Parameters
pathA file/directory path.
dirSepThe directory separator.
Returns
The path towar dthe parent directory.

Definition at line 71 of file FileTools.cpp.

Referenced by ~FileTools().

◆ putStreamIntoVectorOfStrings()

std::vector< std::string > FileTools::putStreamIntoVectorOfStrings ( std::istream &  input)
static

Reads a stream and write each line in a vector.

Parameters
inputInput stream.
Returns
A vector of strings.

Definition at line 94 of file FileTools.cpp.

Referenced by ~FileTools().

Member Data Documentation

◆ DIR_SEP

char FileTools::DIR_SEP = '/'
static

Definition at line 34 of file FileTools.h.


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