Contains functions for creating and deleting files/directories and scanning for files. More...
#include <fileio.h>
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. |
Contains functions for creating and deleting files/directories and scanning for files.
Definition at line 57 of file fileio.h.
int FileIO::CopyFileTo | ( | const std::string & | existingFile, |
const std::string & | newFile | ||
) | [static] |
Copies a file and renames it.
[in] | existingFile | The file to copy. |
[in] | newFile | The new copied file (any existing file is replaced). |
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).
fname | Name of the directory. |
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).
fname | Name of the directory. |
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).
files | Vector of file names of files to delete. |
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).
fname | Name of the file. |
Definition at line 154 of file fileio.cpp.
bool FileIO::FileExists | ( | const std::string & | fname ) | [static] |
Checks if a file exists.
[in] | fname | Name of the file. |
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.
dirs | Vector of all directories found. |
path | The path (directory to search in). |
extractPath | If true, then the path is extracted from the file names. |
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.
files | Vector of files found in directory. |
ext | The search pattern for files (*.*, *.xml, etc). |
path | The path (directory to search in). |
extractPath | If true, then the path is extracted from the file names. |
recursive | If true, method will get files from sub-directories also. |
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.
files | Vector of all data found. |
path | The path (directory to search in). |
extractPath | If true, then the path is extracted from the file names. |
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.
[in] | filename | Name of the file to get the size of. |
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.
src | Source string with path information. |
path | The extracted path. |
Definition at line 193 of file fileio.cpp.
bool FileIO::IsDir | ( | const std::string & | path ) | [static] |
Check if a directory exists.
[in] | path | Directory to check for. |
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.
[in] | name | File name with directory paths (e.g. settings/my_file.csv). |
[in] | mode | Mode options to pass to fopen on file creation. |
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).
[in] | fp | File pointer to read from. |
[out] | columns | The delimited string data read. |
[in] | delimiter | The delimter for separation of data. |
[in] | end | Ending character to signal stop reading. |
[in] | skipBlankEntriesFlag | If 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. |
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.
[in] | str | File stream operator. |
[out] | line | Line read from file (doesn't include carriage return). |
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.
[in] | fp | File pointer to read from. |
[out] | line | Line read from file (doesn't include carriage return). |
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.
[in] | originalName | The file to change the name of. |
[in] | newName | The new file name. |
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.
[in] | str | String to get tokens from. |
[in] | delimiters | Delimter for tokens. |
Definition at line 838 of file fileio.cpp.