GClasses
GClasses::GFile Class Reference

Detailed Description

Contains some useful routines for manipulating files.

#include <GFile.h>

Static Public Member Functions

static void appendToFile (const char *szFilename, const char *szString)
 Appends szString to the specified file. (This is a convenient method for logging. It is not efficient, because it does not keep the file open.) More...
 
static char * clipFilename (char *szBuff)
 This finds the last slash in szBuff and sets it to '\0' and returns szBuff. More...
 
static const char * clipPath (const char *szBuff)
 This finds the last slash in szBuff and returns a pointer to the char past that. (If there are no slashes or back-slashes, it returns szBuff) More...
 
static void condensePath (char *szPath)
 Remove extra ".." folders in the path. More...
 
static bool copyFile (const char *szSrcPath, const char *szDestPath)
 This copies a file. It doesn't check to see if it is overwriting–it just does the copying. On success it returns true. On error it returns false. It won't work with a file bigger than 2GB. Both paths must include the filename. More...
 
static bool deleteFile (const char *szFilename)
 Deletes the specified file. Returns true iff successful. More...
 
static bool doesDirExist (const char *szDir)
 returns true if the directory exists More...
 
static bool doesFileExist (const char *filename)
 returns true if the file exists More...
 
static void fileList (std::vector< std::string > &list, const char *dir=".")
 Adds the names of all the files (excluding folders) in the specified directory to "list". The filenames do not include any path information. More...
 
static void fileListRecursive (std::vector< std::string > &list, const char *dir=".")
 Produces a list of all the files in "dir" recursively. Relative paths to all the files will be added to the list. More...
 
static void folderList (std::vector< std::string > &list, const char *dir=".", bool excludeDots=true)
 Adds the names of all the folders in the specified directory to "list". If excludeDots is true, then folders named "." or ".." will be excluded. The folder names do not include any path information. More...
 
static void folderListRecursive (std::vector< std::string > &list, const char *dir=".")
 Produces a list of all the folders in "dir" recursively, including "dir". Relative paths to all the folders will be added to the list. "dir" is guaranteed to be the first item in the list. More...
 
static char * loadFile (const char *szFilename, size_t *pnSize)
 Loads a file into memory and returns a pointer to the memory. You must delete the buffer it returns. More...
 
static bool localStorageDirectory (char *toHere)
 returns a user's home directory for the various OS's More...
 
static bool makeDir (const char *szDir)
 This is a brute force way to make a directory. It iterates through each subdir in szDir and calls mkdir until it has created the complete set of nested directories. More...
 
static time_t modifiedTime (const char *szFilename)
 This returns the number of seconds since 1970 UTC. More...
 
static void parsePath (const char *szPath, struct PathData *pData)
 Identifies the folder, file, extension, and total length from a path. More...
 
static bool removeDir (const char *szDir)
 Removes the specified directory. Fails if it is not empty. Returns true iff successful. More...
 
static void saveFile (const char *pBuf, size_t nSize, const char *szFilename)
 Saves a buffer as a file. Returns true on success. More...
 
static void setModifiedTime (const char *filename, time_t t)
 Set the last modified time of a file. More...
 
static void tempFilename (char *pBuf)
 returns a temporary filename More...
 

Member Function Documentation

static void GClasses::GFile::appendToFile ( const char *  szFilename,
const char *  szString 
)
static

Appends szString to the specified file. (This is a convenient method for logging. It is not efficient, because it does not keep the file open.)

static char* GClasses::GFile::clipFilename ( char *  szBuff)
static

This finds the last slash in szBuff and sets it to '\0' and returns szBuff.

static const char* GClasses::GFile::clipPath ( const char *  szBuff)
static

This finds the last slash in szBuff and returns a pointer to the char past that. (If there are no slashes or back-slashes, it returns szBuff)

static void GClasses::GFile::condensePath ( char *  szPath)
static

Remove extra ".." folders in the path.

static bool GClasses::GFile::copyFile ( const char *  szSrcPath,
const char *  szDestPath 
)
static

This copies a file. It doesn't check to see if it is overwriting–it just does the copying. On success it returns true. On error it returns false. It won't work with a file bigger than 2GB. Both paths must include the filename.

static bool GClasses::GFile::deleteFile ( const char *  szFilename)
static

Deletes the specified file. Returns true iff successful.

static bool GClasses::GFile::doesDirExist ( const char *  szDir)
static

returns true if the directory exists

static bool GClasses::GFile::doesFileExist ( const char *  filename)
static

returns true if the file exists

static void GClasses::GFile::fileList ( std::vector< std::string > &  list,
const char *  dir = "." 
)
static

Adds the names of all the files (excluding folders) in the specified directory to "list". The filenames do not include any path information.

static void GClasses::GFile::fileListRecursive ( std::vector< std::string > &  list,
const char *  dir = "." 
)
static

Produces a list of all the files in "dir" recursively. Relative paths to all the files will be added to the list.

static void GClasses::GFile::folderList ( std::vector< std::string > &  list,
const char *  dir = ".",
bool  excludeDots = true 
)
static

Adds the names of all the folders in the specified directory to "list". If excludeDots is true, then folders named "." or ".." will be excluded. The folder names do not include any path information.

static void GClasses::GFile::folderListRecursive ( std::vector< std::string > &  list,
const char *  dir = "." 
)
static

Produces a list of all the folders in "dir" recursively, including "dir". Relative paths to all the folders will be added to the list. "dir" is guaranteed to be the first item in the list.

static char* GClasses::GFile::loadFile ( const char *  szFilename,
size_t *  pnSize 
)
static

Loads a file into memory and returns a pointer to the memory. You must delete the buffer it returns.

static bool GClasses::GFile::localStorageDirectory ( char *  toHere)
static

returns a user's home directory for the various OS's

static bool GClasses::GFile::makeDir ( const char *  szDir)
static

This is a brute force way to make a directory. It iterates through each subdir in szDir and calls mkdir until it has created the complete set of nested directories.

static time_t GClasses::GFile::modifiedTime ( const char *  szFilename)
static

This returns the number of seconds since 1970 UTC.

static void GClasses::GFile::parsePath ( const char *  szPath,
struct PathData pData 
)
static

Identifies the folder, file, extension, and total length from a path.

static bool GClasses::GFile::removeDir ( const char *  szDir)
static

Removes the specified directory. Fails if it is not empty. Returns true iff successful.

static void GClasses::GFile::saveFile ( const char *  pBuf,
size_t  nSize,
const char *  szFilename 
)
static

Saves a buffer as a file. Returns true on success.

static void GClasses::GFile::setModifiedTime ( const char *  filename,
time_t  t 
)
static

Set the last modified time of a file.

static void GClasses::GFile::tempFilename ( char *  pBuf)
static

returns a temporary filename