charon-core  0.3.1
FileTool Namespace Reference

Useful functions when working with files. More...

Functions

int charon_core_DLL_PUBLIC changeDir (const std::string &dir)
 Change current working directory. More...
 
bool charon_core_DLL_PUBLIC exists (const std::string &file)
 Check if file exists. More...
 
std::string charon_core_DLL_PUBLIC getCurrentDir ()
 Get current working directory. More...
 
std::vector< std::string >
charon_core_DLL_PUBLIC 
getFilesWithSuffix (std::string suffix)
 Search files with given suffix. More...
 
int charon_core_DLL_PUBLIC makeDir (const std::string &dir)
 Create a new directory using MODE 711 (in unix) More...
 
int charon_core_DLL_PUBLIC makePath (std::string &path)
 This function creates all directories contained in path provided they do not already exist. More...
 
std::string charon_core_DLL_PUBLIC readFile (const std::string &fName)
 read file content into std::string More...
 
int charon_core_DLL_PUBLIC remove (const std::string &file)
 Remove file. More...
 
int charon_core_DLL_PUBLIC rename (const std::string &oldFile, const std::string &newFile)
 Rename file. More...
 
void charon_core_DLL_PUBLIC slashConvert (std::string &src)
 Convert unix to windows paths and reversed. More...
 

Variables

const char charon_core_DLL_PUBLIC slash = '\\'
 Slash of current operating system ("/" or "\")
 

Detailed Description

This wraps the operating system specific functions.

Function Documentation

int FileTool::changeDir ( const std::string &  dir)
Parameters
dirnew working directory
Returns
result of chdir

Definition at line 91 of file FileTool.cpp.

bool FileTool::exists ( const std::string &  file)
Parameters
filename of the file to look for
Returns
true if file exists, otherwise false

Definition at line 154 of file FileTool.cpp.

std::string FileTool::getCurrentDir ( )
Returns
string containing current working directory

Definition at line 95 of file FileTool.cpp.

std::vector< std::string > FileTool::getFilesWithSuffix ( std::string  suffix)

Iterates through the files of the current working directory and looks for files with the given suffix.

Parameters
suffixSuffix of the requested files
Returns
Vector containing the file names

Definition at line 104 of file FileTool.cpp.

int FileTool::makeDir ( const std::string &  dir)
Parameters
dirname of the directory to create
Returns
result of mkdir

Definition at line 87 of file FileTool.cpp.

int FileTool::makePath ( std::string &  path)
Parameters
pathpath to create
Returns
result of final mkdir

Definition at line 71 of file FileTool.cpp.

References StringTool::explode(), makeDir(), slash, and slashConvert().

std::string FileTool::readFile ( const std::string &  fName)

Reads a file and writes it into a std::string.

Parameters
fNameFile to read
Returns
Content of the file

Definition at line 167 of file FileTool.cpp.

int FileTool::remove ( const std::string &  file)
Parameters
filename of the file to remove
Returns
result of unlink

Definition at line 159 of file FileTool.cpp.

int FileTool::rename ( const std::string &  oldFile,
const std::string &  newFile 
)
Parameters
oldFilename of the file to rename
newFilenew name
Returns
result of rename

Definition at line 163 of file FileTool.cpp.

void FileTool::slashConvert ( std::string &  src)

The direction is determined by the current running operating system.

Parameters
srcsource string to convert (will be modified)

Definition at line 145 of file FileTool.cpp.

References slash.