C12Adapter Opensource C++ Interface
MFindFile Class Reference

Operating system and compiler independent way to search for file or directory. More...

Public Member Functions

 MFindFile ()
 Default constructor, no search is initialized.
 
 MFindFile (MConstChars directory, MConstChars fileMask, bool searchForDirectories=false, bool reserved=false, bool excludeDotFiles=false)
 Constructor, which initializes the search. More...
 
 ~MFindFile ()
 Object destructor.
 
void Close ()
 Close the result of the previous search. More...
 
void Init (MConstChars directory, MConstChars fileMask, bool searchForDirectories=false, bool reserved=false, bool excludeDotFiles=false)
 Initialize the search. More...
 
MConstChars FindNext (bool returnFullPath=true)
 Find the next file that corresponds to the initialization parameters of the object. More...
 

Static Public Member Functions

static void Populate (MStdStringVector &result, const MStdString &directory, const MStdString &fileMask, bool searchForDirectories=false, bool reserved=false, bool excludeDotFiles=false)
 Populate the result vector with files from the given directory. More...
 

Detailed Description

Operating system and compiler independent way to search for file or directory.

Constructor & Destructor Documentation

MFindFile::MFindFile ( MConstChars  directory,
MConstChars  fileMask,
bool  searchForDirectories = false,
bool  reserved = false,
bool  excludeDotFiles = false 
)

Constructor, which initializes the search.

It is not an error if the directory does not exist. In this case, FindNext returns NULL.

Parameters
directoryPath to a directory where to search for files or subdirectories. It can be full path or path relative to current directory.
fileMaskThe file mask cannot contain a subdirectory. Regular file mask syntax applies, * and ? can be used for a sequence of characters and for a single character.
searchForDirectoriesWhen true, the search is done for directories only. Otherwise, when false, the search is done only for ordinary files.
reservedReserved parameter that has no effect.
excludeDotFilesSpecial directories '.' and '..' are never listed, but when this parameter is true, any file that starts with period, such as ".svn", will not appear in the result search.
See also
Init - initialize the search after the object has been constructed

Member Function Documentation

void MFindFile::Close ( )

Close the result of the previous search.

It is always safe to call Close, any number of times.

MConstChars MFindFile::FindNext ( bool  returnFullPath = true)

Find the next file that corresponds to the initialization parameters of the object.

Note that the storage for the file name is allocated inside the class. It should not be attempted to be deleted.

If the search for directories was initiated, then the file returned is a directory name, otherwise this is non-directory name.

Parameters
returnFullPathIf true, return the full path. Otherwise, return only file and extension.
void MFindFile::Init ( MConstChars  directory,
MConstChars  fileMask,
bool  searchForDirectories = false,
bool  reserved = false,
bool  excludeDotFiles = false 
)

Initialize the search.

It is not an error if the directory does not exist. In this case, FindNext returns NULL.

Parameters
directoryPath to a directory where to search for files or subdirectories. It can be full path or path relative to current directory.
fileMaskThe file mask cannot contain a subdirectory. Regular file mask syntax applies, * and ? can be used for a sequence of characters and for a single character.
searchForDirectoriesWhen true, the search is done for directories only. Otherwise, when false, the search is done only for ordinary files.
reservedReserved parameter that has no effect.
excludeDotFilesSpecial directories '.' and '..' are never listed, but when this parameter is true, any file that starts with period, such as ".svn", will not appear in the result search.
static void MFindFile::Populate ( MStdStringVector result,
const MStdString directory,
const MStdString fileMask,
bool  searchForDirectories = false,
bool  reserved = false,
bool  excludeDotFiles = false 
)
inlinestatic

Populate the result vector with files from the given directory.

This method combines the search initializer with FindNext.

Parameters
resultString vector, shall be empty prior to this call, will be populated with file names.
directoryPath to a directory where to search for files or subdirectories. It can be full path or path relative to current directory.
fileMaskThe file mask cannot contain a subdirectory. Regular file mask syntax applies, * and ? can be used for a sequence of characters and for a single character.
searchForDirectoriesWhen true, the search is done for directories only. Otherwise, when false, the search is done only for ordinary files.
reservedReserved parameter that has no effect.
excludeDotFilesSpecial directories '.' and '..' are never listed, but when this parameter is true, any file that starts with period, such as ".svn", will not appear in the result search.