Class FileSystem

Index Home MAE > MAE Architecture > MAE Data Types > Class Index > Class FileSystem

Summary
Public Properties
Public Methods
static int getFileList(pathName, filenameMask, fileList, stripped)
static int getFileListRE(pathName, filenameMaskRE, fileList, fIsExtendedExpr, fIsCaseSensitive)
static int getFileList(pathNames, filenameMask, fileList)
static int getFileListRE(pathNames, filenameMaskRE, fileList, fIsExtendedExpr, fIsCaseSensitive)
static string getFilenameDir(fullFilename)
static string getBaseFilename(fullFilename)
static bool checkDirectoryNameOK(fullDirname)
static bool checkFileReadable(filename)
static bool checkFileWritable(filename)
static bool fileExists(filename)
static long size(filename)
static string fileDiagnose(filename)
static bool makeDirectory(fullDirname)
static vector portableGrep(text, filename, fCaseSensitive, fExtendedRegularExpr)
static bool isLegalFileName(filename, explanation)
static bool mvFile(sourceFile, destFile)
static bool rmFile(sourceFile)
static unsigned int readTextFile(filenameToRead, linesRead, fStripLeadTrailWS, maxLinesToRead)
static const string getFileContents(filename, offset)
static const string getFileContents(f, offset)
static bool putFileContents(filenameToSave, content)
static bool putFileContents(filenameToSave, content)
static string basename(filename)
static string getOSEnv(var, defaultValue)
static int system(cmd)
static int systemSlim(cmd)
static FILE* pipeOpen(cmd, flags)
static string find_first_file_name(path, filename_mask)
static string find_next_file_name()
static StringSet dirFilenames(path, filename_mask, hiddenFilesOK)
static long filelength(filename)

#include <FileSystem.h >

Summary

General class for file system related methods

Mostly static methods

Public Properties

static const char separatorChar

File path parts separator, e.g. /

static const string separator

File path parts separator, e.g. /


Public Methods

static int getFileList(pathName, filenameMask, fileList, stripped)

const string& pathName

The path to search for the files

const string& filenameMask

The filemask of the files we are searching for

vector fileList

Vector to which to add the filenames found. This vector is not cleared in order to allow accumulation of results

const bool stripped

Whether we should strip off the directory name and the file extension from the results stored in the vector, e.g /a/b/foo.mask is just foo

Default value: false


Searches the the specified path for the files that satisfy the specified filemask and adds their names to the fileList vector

Return value: The number of filenames added to the fileList vector

static int getFileListRE(pathName, filenameMaskRE, fileList, fIsExtendedExpr, fIsCaseSensitive)

const string& pathName

The path to search for the files

const string& filenameMaskRE

The filemask regular expression of the files we are searching for

vector fileList

Vector to which to add the filenames found. This vector is not cleared in order to allow accumulation of results

bool fIsExtendedExpr

true means the regular expression is an extended regular

Default value: true

bool fIsCaseSensitive

true means evaluation of regular expression should

Default value: true


Searches the the specified path for the files that satisfy the specified filemask regular expression and adds their names to the fileList vector

Return value: The number of filenames added to the fileList vector

static int getFileList(pathNames, filenameMask, fileList)

const vector pathNames

The paths to search for the files

const string& filenameMask

The filemask of the files we are searching for

vector fileList

Vector to which to add the filenames found. This vector is not cleared in order to allow accumulation of results


Searches the the specified paths for the files that satisfy the specified filemask and adds their names to the fileList vector

Return value: The number of filenames added to the fileList vector

static int getFileListRE(pathNames, filenameMaskRE, fileList, fIsExtendedExpr, fIsCaseSensitive)

const vector pathNames

The paths to search for the files expression allowing use of | char and other extensions

const string& filenameMaskRE

The filemask regular expression of the files we are searching for be done in a case sensitive manner

vector fileList

Vector to which to add the filenames found. This vector is not cleared in order to allow accumulation of results

bool fIsExtendedExpr

true means the regular expression is an extended regular

Default value: true

bool fIsCaseSensitive

true means evaluation of regular expression should

Default value: true


Searches the the specified paths for the files that satisfy the specified filemask regular expression and adds their names to the fileList vector

Return value: The number of filenames added to the fileList vector

static string getFilenameDir(fullFilename)

const string& fullFilename

the fully or partially qualified filename to parse


Get the path of a fully or partially qualified filename.

Return value: the path of the filename (with no trailling /), which may be "." if not known.

static string getBaseFilename(fullFilename)

const string& fullFilename

the fully or partially qualified filename to parse


Get the unqualified portion, no path or drive info, of a fully or partially qualified filename

Return value: the unqualified filename.ext

static bool checkDirectoryNameOK(fullDirname)

const string& fullDirname

The name of the directory you want to check.


Test if a directory exists and is readable.

Return value: true if it exists.

static bool checkFileReadable(filename)

const string& filename

The name of the file.


Check whether a file is readable

Return value: true if the file exists and is readable, false otherwise.

static bool checkFileWritable(filename)

const string& filename

The name of the file.


Check to see if a file is writable

Return value: true if the file is writable, false otherwise.

static bool fileExists(filename)

const string& filename

the name of the file to check for


Check to see if a file exists

Return value: false if the file does not exist or if we do not have permission

static long size(filename)

const string& filename

the name of a valid file in the file system


Return the size of the specified file.

Return value: length (in bytes) of file; -1 on error

static string fileDiagnose(filename)

const string& filename

the filename to diagnose


Return, as a string, a bunch of diagnostic information, such as who owns a file and whatnot. For informational uses when things go wrong. Note that the string contains HTML formatting information for now; strip it out if undesired.

Return value: diagnostic info

static bool makeDirectory(fullDirname)

const string& fullDirname

the full directory name


Make the requested directory name.  If the directory already exists, return false, otherwise return true.  This method is pretty stupid right now, and doesn't do much in the way of error checking.

Return value: true upon success

static vector <string > portableGrep(text, filename, fCaseSensitive, fExtendedRegularExpr)

const string& text

the text to search for

const string& filename

the file to search

bool fCaseSensitive

(parameter ignored)

Default value: true

bool fExtendedRegularExpr

(parameter ignored)

Default value: false


This function 'greps' for text in a file, and returns a vector of all lines that have that text. Note:

1) It's case sensitive

2) Exact match only; regular expressions are not understood

Return value: a list of lines that match

static bool isLegalFileName(filename, explanation)

const string& filename

the filename to check

string& explanation

if not legal, an explanation of what's wrong with it


Determine if a filename is legal. If the filename is not legal, the method will return false, and explanation will contain the reason for the failure.

Return value: true if the filename is legal.

static bool mvFile(sourceFile, destFile)

const string& sourceFile

filename with contents to move

const string& destFile

destination filename


Move sourceFile to destFile, overwriting if necessary.

Return value: true if accomplished, false for failure.

static bool rmFile(sourceFile)

const string& sourceFile

filename to remove


Remove the named file

Return value: true on success, false on failure

static unsigned int readTextFile(filenameToRead, linesRead, fStripLeadTrailWS, maxLinesToRead)

const string& filenameToRead

filename to read

vector linesRead

bool fStripLeadTrailWS

Flag: strip leading/trailing whitespace

Default value: false

unsigned int maxLinesToRead

maximum number of lines to read

Default value: 0


Read a file into an array of strings.

@param liensRead - (output) file content read

Return value: number of lines read

static const string getFileContents(filename, offset)

const string& filename

filename to read

long offset

offset into file to begin

Default value: 0


Read a file into a string.

Return value: file content read

static const string getFileContents(f, offset)

FILE* f

a pointer to an open file

long offset

offset into file to begin

Default value: 0


Read a file into a string.

Return value: file content read

static bool putFileContents(filenameToSave, content)

const string& filenameToSave

filename to write content to

const string& content

the file content to save


Save a string as the total contents of the named file

Return value: true on success, false on failure

static bool putFileContents(filenameToSave, content)

const string& filenameToSave

filename to write content to

const vector <string >& content

the file content to save


Save a vector of strings as the total contents of the named file

Return value: true on success, false on failure

static string basename(filename)

const string& filename

input filename


Return just the file name (no path) of the named file.

Return value: base filename without path

static string getOSEnv(var, defaultValue)

const string& var

the variable name to fetched

const string& defaultValue

if variable undefined or blank, return this value instead


Query an environment variable from the key file environ.conf.

Return value: value of environment variable (or defaultValue)

static int system(cmd)

string cmd

the command to execute


Build the string to run a command through system via ksh after sourcing environ.conf.

Return value: 0 upon success, -1 on error, 1+ return code from command (see ::system())

static int systemSlim(cmd)

const string& cmd

the command to execute


Execute a the command on the command line.

Return value: 0 upon success, -1 on error, 1+ return code from command (see ::system())

static FILE* pipeOpen(cmd, flags)

string cmd

the command to execute

const string& flags

type type of pipe to open to command, e.g. r, w, or rw


Build the string to run a command through a pipe

Return value: a FILE* to pipe; use ::pclose() to close it

static string find_first_file_name(path, filename_mask)

const string& path

path to search

const string& filename_mask

mask for filtering files


Return NULL if no files match /filename_mask/.  Return first file in directory which matches /filename_mask/.  The pointer is not malloc()ed and should NOT be free()ed by you. /filename_mask/ can  contain an asterisk as a wild card position, e.g.  *.c, base.*, this*that, etc.  The ? wildcard will match any one character, e.g.  ???.c.  The . character matches only the . character.  activated:  Otherwise, /filename_mask/ can be a regular expression (see grep(1V)).

Return value: the next filename, null string at end of list

static string find_next_file_name()

If you are seeking multiple file names and you have already fetched the first one with find_first_file_name(), then call this routine for the next one.  NULL is returned when there are no more maching names.

Return value: the next filename, null string at end of list

static StringSet dirFilenames(path, filename_mask, hiddenFilesOK)

const string& path

directory path to search

const string& filename_mask

mask for files, e.g. *.txt, sda????.dat

Default value: "*"

bool hiddenFilesOK

true to include hidden files that start with dot, false to exclude them

Default value: false


Create a list of filenames matching the filename_mask for the particular directory path.  NULL is returned if no names matched or if path is incorrect or filename_mask is NULL.

static long filelength(filename)

const string& filename


Determine the size of the named file

Return value: file size upon success, -1 upon failure