bpp-core  2.1.0
bpp::FileTools Class Reference

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

#include <Bpp/Io/FileTools.h>

List of all members.

Public Member Functions

 FileTools ()
virtual ~FileTools ()

Static Public Member Functions

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

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 67 of file FileTools.h.


Constructor & Destructor Documentation

Definition at line 73 of file FileTools.h.

virtual bpp::FileTools::~FileTools ( ) [inline, virtual]

Definition at line 74 of file FileTools.h.


Member Function Documentation

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 64 of file FileTools.cpp.

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 54 of file FileTools.cpp.

Referenced by bpp::ApplicationTools::getAFilePath().

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 120 of file FileTools.cpp.

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 74 of file FileTools.cpp.

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 93 of file FileTools.cpp.

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

Get the next non-blanck line of a stream.

Parameters:
inInput stream.

Definition at line 142 of file FileTools.cpp.

References bpp::TextTools::isEmpty().

Referenced by bpp::DataTable::read().

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 105 of file FileTools.cpp.

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 128 of file FileTools.cpp.


Member Data Documentation

char FileTools::DIR_SEP = '/' [static]

Definition at line 70 of file FileTools.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Friends