Static Public Member Functions

CxUtils::FileIO Class Reference

Contains functions for creating and deleting files/directories and scanning for files. More...

#include <fileio.h>

List of all members.

Static Public Member Functions

static int CreateDir (const std::string &fname)
 Creates a directory with the filename. The directory is created relative to the working directory of the program, unless an absolute path is included in the file name (ex: C:/temp).
static int DeleteDir (const std::string &fname)
 Deletes a directory with the filename. The directory is created relative to the working directory of the program, unless an absolute path is included in the file name (ex: C:/temp).
static int DeleteFiles (const std::string &fname)
 Deletes a file based on name. The file is relative to the working directory of the program, unless an absolute path is included in the file name (ex: C:/temp.log.txt).
static int DeleteFiles (const std::vector< std::string > &files)
 Deletes files based on names. The files are treated relative to the working directory of the program, unless an absolute path is included in the file name (ex: C:/temp.log.txt).
static int GetPath (const std::string &src, std::string &path)
 Gets the file path from a string.
static int GetFiles (std::vector< std::string > &files, const std::string &ext="*.*", const std::string &path="", const bool extractPath=true, const bool recursive=false)
 Reads the list of all files in a directory.
static int GetDirectories (std::vector< std::string > &dirs, const std::string &path, const bool extractPath=false)
 Reads the list of all directories in a folder.
static int GetFilesAndDirectories (std::vector< std::string > &files, const std::string &path="", const bool extractPath=true)
 Reads the list of all data in a directory.
static FILE * Open (const std::string &name, const std::string &mode="wt")
 Creates a file with options, but creates any directories needed also.
static bool IsDir (const std::string &path)
 Check if a directory exists.
static int RenameFile (const std::string &originalName, const std::string &newName)
 Copies a file and renames it.
static int CopyFileTo (const std::string &existingFile, const std::string &newFile)
 Copies a file and renames it.
static unsigned int GetFileSizeBytes (const std::string &fileName)
 Gets the size of a file in bytes.
static unsigned int ParseDelimitedLine (FILE *fp, std::vector< std::string > &columns, const char delimiter= ',', const char end= '\n', const bool skipBlankEntriesFlag=true)
 Reads a line in a file up to the end of file or the provided ending character (default is carriage return).
static unsigned int ReadLine (FILE *fp, std::string &line)
 Reads a line from a FILE pointer adding it to a string, reading up to a newline character.
static unsigned int ReadLine (std::fstream &str, std::string &line)
 Reads a line from a fstream adding it to a string, reading up to a newline character.
static std::vector< std::string > Tokenize (const std::string &str, const std::string &delimter)
 Tokenize a string.
static bool FileExists (const std::string &fname)
 Checks if a file exists.

Detailed Description

Contains functions for creating and deleting files/directories and scanning for files.

Definition at line 57 of file fileio.h.


Member Function Documentation

int FileIO::CopyFileTo ( const std::string &  existingFile,
const std::string &  newFile 
) [static]

Copies a file and renames it.

Parameters:
[in]existingFileThe file to copy.
[in]newFileThe new copied file (any existing file is replaced).
Returns:
1 on success, false on failure./home/dbarber/Software/ACTIVE-IST/libraries/cxutils/trunk/1.0/lib

Definition at line 649 of file fileio.cpp.

int FileIO::CreateDir ( const std::string &  fname ) [static]

Creates a directory with the filename. The directory is created relative to the working directory of the program, unless an absolute path is included in the file name (ex: C:/temp).

Parameters:
fnameName of the directory.
Returns:
1 if created, otherwise 0.

Definition at line 78 of file fileio.cpp.

int FileIO::DeleteDir ( const std::string &  fname ) [static]

Deletes a directory with the filename. The directory is created relative to the working directory of the program, unless an absolute path is included in the file name (ex: C:/temp).

Parameters:
fnameName of the directory.
Returns:
1 if deleted, otherwise 0.

Definition at line 128 of file fileio.cpp.

int FileIO::DeleteFiles ( const std::vector< std::string > &  files ) [static]

Deletes files based on names. The files are treated relative to the working directory of the program, unless an absolute path is included in the file name (ex: C:/temp.log.txt).

Parameters:
filesVector of file names of files to delete.
Returns:
Number of files deleted, otherwise 0.

Definition at line 171 of file fileio.cpp.

int FileIO::DeleteFiles ( const std::string &  fname ) [static]

Deletes a file based on name. The file is relative to the working directory of the program, unless an absolute path is included in the file name (ex: C:/temp.log.txt).

Parameters:
fnameName of the file.
Returns:
1 if deleted, otherwise 0.

Definition at line 154 of file fileio.cpp.

bool FileIO::FileExists ( const std::string &  fname ) [static]

Checks if a file exists.

Parameters:
[in]fnameName of the file.
Returns:
True if exists, false if does not.

Definition at line 898 of file fileio.cpp.

int FileIO::GetDirectories ( std::vector< std::string > &  dirs,
const std::string &  path,
const bool  extractPath = false 
) [static]

Reads the list of all directories in a folder.

Parameters:
dirsVector of all directories found.
pathThe path (directory to search in).
extractPathIf true, then the path is extracted from the file names.
Returns:
Number of files loaded.

Definition at line 356 of file fileio.cpp.

int FileIO::GetFiles ( std::vector< std::string > &  files,
const std::string &  ext = "*.*",
const std::string &  path = "",
const bool  extractPath = true,
const bool  recursive = false 
) [static]

Reads the list of all files in a directory.

Parameters:
filesVector of files found in directory.
extThe search pattern for files (*.*, *.xml, etc).
pathThe path (directory to search in).
extractPathIf true, then the path is extracted from the file names.
recursiveIf true, method will get files from sub-directories also.
Returns:
Number of files loaded.

Definition at line 235 of file fileio.cpp.

int FileIO::GetFilesAndDirectories ( std::vector< std::string > &  files,
const std::string &  path = "",
const bool  extractPath = true 
) [static]

Reads the list of all data in a directory.

Parameters:
filesVector of all data found.
pathThe path (directory to search in).
extractPathIf true, then the path is extracted from the file names.
Returns:
Number of files loaded.

Definition at line 470 of file fileio.cpp.

unsigned int FileIO::GetFileSizeBytes ( const std::string &  filename ) [static]

Gets the size of a file in bytes.

Parameters:
[in]filenameName of the file to get the size of.
Returns:
Number of bytes contained in the file, 0 if none or file doesn't exist.

Definition at line 683 of file fileio.cpp.

int FileIO::GetPath ( const std::string &  src,
std::string &  path 
) [static]

Gets the file path from a string.

Parameters:
srcSource string with path information.
pathThe extracted path.
Returns:
1 if path retrieved, otherwise 0.

Definition at line 193 of file fileio.cpp.

bool FileIO::IsDir ( const std::string &  path ) [static]

Check if a directory exists.

Parameters:
[in]pathDirectory to check for.
Returns:
True if the path is a valid directory, false otherwise.

Definition at line 601 of file fileio.cpp.

FILE * FileIO::Open ( const std::string &  name,
const std::string &  mode = "wt" 
) [static]

Creates a file with options, but creates any directories needed also.

Parameters:
[in]nameFile name with directory paths (e.g. settings/my_file.csv).
[in]modeMode options to pass to fopen on file creation.
Returns:
Valid file pointer on success, NULL on failure.

Definition at line 571 of file fileio.cpp.

unsigned int FileIO::ParseDelimitedLine ( FILE *  fp,
std::vector< std::string > &  columns,
const char  delimiter = ',',
const char  end = '\n',
const bool  skipBlankEntriesFlag = true 
) [static]

Reads a line in a file up to the end of file or the provided ending character (default is carriage return).

Parameters:
[in]fpFile pointer to read from.
[out]columnsThe delimited string data read.
[in]delimiterThe delimter for separation of data.
[in]endEnding character to signal stop reading.
[in]skipBlankEntriesFlagIf true, blank entries (e.g. ",,") that have not characters between delimeter are not added to output vector. If false, empty strings are placed into output columns vector.
Returns:
Number of elements read from the line, 0 if nothing.

Definition at line 711 of file fileio.cpp.

unsigned int FileIO::ReadLine ( std::fstream &  str,
std::string &  line 
) [static]

Reads a line from a fstream adding it to a string, reading up to a newline character.

Parameters:
[in]strFile stream operator.
[out]lineLine read from file (doesn't include carriage return).
Returns:
Number of characters read.

Definition at line 804 of file fileio.cpp.

unsigned int FileIO::ReadLine ( FILE *  fp,
std::string &  line 
) [static]

Reads a line from a FILE pointer adding it to a string, reading up to a newline character.

Parameters:
[in]fpFile pointer to read from.
[out]lineLine read from file (doesn't include carriage return).
Returns:
Number of characters read.

Definition at line 770 of file fileio.cpp.

int FileIO::RenameFile ( const std::string &  originalName,
const std::string &  newName 
) [static]

Copies a file and renames it.

Parameters:
[in]originalNameThe file to change the name of.
[in]newNameThe new file name.
Returns:
1 on success, false on failure.

Definition at line 632 of file fileio.cpp.

std::vector< std::string > FileIO::Tokenize ( const std::string &  str,
const std::string &  delimiters 
) [static]

Tokenize a string.

Parameters:
[in]strString to get tokens from.
[in]delimitersDelimter for tokens.
Returns:
Vector of token strings.

Definition at line 838 of file fileio.cpp.


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