dtUtil::FileUtils Class Reference

#include <fileutils.h>

List of all members.

Public Member Functions

bool FileExists (const std::string &strFile) const
 
Parameters:
strFile the path to the file to check.

void FileCopy (const std::string &strSrc, const std::string &strDest, bool bOverwrite) const
 Copys a file.
void FileMove (const std::string &strSrc, const std::string &strDest, bool bOverwrite) const
 Moves a file.
void FileDelete (const std::string &strFile) const
 Deletes the given file.
struct FileInfo GetFileInfo (const std::string &strFile) const
 
Note:
If the file is not found, the fileType value will be set to FILE_NOT_FOUND and all other values will be undefined.

void ChangeDirectory (const std::string &path)
 Changes the current directory to the one given in "path." This will clear the stack of directories that is set by pushDirectory and popDirectory.
const std::string & CurrentDirectory () const
 
Returns:
the full path to the current directory.

void PushDirectory (const std::string &path)
 Changes the current directory to the one given in "path" and adds the previous current directory to an internal stack so it can be returned to via popDirectory.
void PopDirectory ()
 sets the current directory to the last directory on the stack.
const std::string GetAbsolutePath (const std::string &relativePath) const
 Converts a relative path to an absolute path.
DirectoryContents DirGetFiles (const std::string &path) const
 Note: throws exceptions of type dtUtil::Exception.
DirectoryContents DirGetSubs (const std::string &path) const
 
Parameters:
path the path to the directory to get the subdirectories for.

void DirCopy (const std::string &srcPath, const std::string &destPath, bool bOverwrite, bool copyContentsOnly=false) const
 Copys an entire directory.
bool DirDelete (const std::string &strDir, bool bRecursive)
 Deletes a directory.
void MakeDirectory (const std::string &strDir) const
 creates a new directory from a path.
bool DirExists (const std::string &strDir) const
 
Parameters:
strDir The directory to check.

std::string RelativePath (const std::string &absolutePath, const std::string &file) const
 Helper function that returns the relative path between absolutePath and file.

Static Public Member Functions

static FileUtilsGetInstance ()
 Character separating the parts of a file path.

Static Public Attributes

static const char PATH_SEPARATOR = '/'


Member Function Documentation

static FileUtils& dtUtil::FileUtils::GetInstance ( void   )  [inline, static]

Character separating the parts of a file path.

Returns:
the single instance of this class..

bool dtUtil::FileUtils::FileExists ( const std::string &  strFile  )  const

Parameters:
strFile the path to the file to check.

Returns:
true if the file exists.

void dtUtil::FileUtils::FileCopy ( const std::string &  strSrc,
const std::string &  strDest,
bool  bOverwrite 
) const

Copys a file.

Parameters:
strSrc The path to the source file.
strDest The path to the destination file or directory.
bOverwrite true if this call should overwrite the destination file if it exists.
Exceptions:
FileExceptionEnum::FileNotFound if the source file is not found.
FileExceptionEnum::IOException if an error occurs copying the data or bOverwrite was false and the destination file exists.

void dtUtil::FileUtils::FileMove ( const std::string &  strSrc,
const std::string &  strDest,
bool  bOverwrite 
) const

Moves a file.

This call will attempt to move the file without moving the data, but if it can't, the file will first be copied then the source file will be removed.

Parameters:
strSrc The path to the source file
strDest The path to the destintion file or directory
bOverwrite true if this call should overwrite the destination file if it exists.
Exceptions:
FileExceptionEnum::FileNotFound if the source file is not found.
FileExceptionEnum::IOException if an error occurs moving the data or bOverwrite was false and the destination file exists.

void dtUtil::FileUtils::FileDelete ( const std::string &  strFile  )  const

Deletes the given file.

Parameters:
strFile the path to the file to delete
Exceptions:
FileExceptionEnum::IOException if an error occurs deleting the data

struct FileInfo dtUtil::FileUtils::GetFileInfo ( const std::string &  strFile  )  const [read]

Note:
If the file is not found, the fileType value will be set to FILE_NOT_FOUND and all other values will be undefined.

Returns:
the fileInfo struct for the given file.
See also:
dtUtil::FileInfo

void dtUtil::FileUtils::ChangeDirectory ( const std::string &  path  ) 

Changes the current directory to the one given in "path." This will clear the stack of directories that is set by pushDirectory and popDirectory.

If this call fails, the stack will not be cleared.

See also:
pushDirectory

popDirectory

Parameters:
path The path to the new directory.
Exceptions:
FileExceptionEnum::FileNotFound if the path does not exist.

const std::string & dtUtil::FileUtils::CurrentDirectory (  )  const

Returns:
the full path to the current directory.

void dtUtil::FileUtils::PushDirectory ( const std::string &  path  ) 

Changes the current directory to the one given in "path" and adds the previous current directory to an internal stack so it can be returned to via popDirectory.

If this call fails, the stack will not be changed.

See also:
popDirectory
Parameters:
path The path to the new directory.
Exceptions:
FileExceptionEnum::FileNotFound if the path does not exist.

void dtUtil::FileUtils::PopDirectory (  ) 

sets the current directory to the last directory on the stack.

See also:
pushDirectory
Exceptions:
FileExceptionEnum::FileNotFound if the previous directory no longer exists.

const std::string dtUtil::FileUtils::GetAbsolutePath ( const std::string &  relativePath  )  const

Converts a relative path to an absolute path.

Parameters:
relativePath the relative path to convert to absolute.
Returns:
the absolute path.
Exceptions:
FileExceptionEnum::FileNotFound if the path does not exist.

DirectoryContents dtUtil::FileUtils::DirGetFiles ( const std::string &  path  )  const

Note: throws exceptions of type dtUtil::Exception.

Parameters:
path the path to the directory to list the contents of.
Returns:
a vector of file names.
Exceptions:
FileExceptionEnum::FileNotFound if the path does not exist.
FileExceptionEnum::IOException if the path is not an actual directory

DirectoryContents dtUtil::FileUtils::DirGetSubs ( const std::string &  path  )  const

Parameters:
path the path to the directory to get the subdirectories for.

Returns:
a vector holding the list of subdirectories.
Exceptions:
FileExceptionEnum::FileNotFound if the path does not exist.

void dtUtil::FileUtils::DirCopy ( const std::string &  srcPath,
const std::string &  destPath,
bool  bOverwrite,
bool  copyContentsOnly = false 
) const

Copys an entire directory.

If destPath exists, then a subdirectory will be created in destPath with the same name as srcPath unless copyContentsOnly is true, in which case the contents of srcPath will be copied into destPath. If destPath does not exist, destPath will be created if the parent exists and the contents of srcPath will be copied to destPath whether copyContentsOnly is true or false.

Parameters:
srcPath the source directory to copy.
destPath the destination directory.
bOverwrite true if this call should overwrite the destination file if it exists.
copyContentsOnly true if the contents of srcPath should be copied into destPath rather than create a subdirectory
Exceptions:
FileExceptionEnum::FileNotFound if the source file is not found.
FileExceptionEnum::IOException if an error occurs copying the data or bOverwrite was false and a destination file exists.

bool dtUtil::FileUtils::DirDelete ( const std::string &  strDir,
bool  bRecursive 
)

Deletes a directory.

If bRecursive is true, the directory and all it's contents will be removed. If it's false, the call will fail unless the directory is empty.

Parameters:
strDir The path of the directory to delete.
bRecursive true if the directory should be deleted recursively.
Returns:
true if successful or false if the directory is NOT empty and bRecursive is false.
Exceptions:
FileExceptionEnum::FileNotFound if the path does not exist.
FileExceptionEnum::IOException if an error occurs deleteting the directory

void dtUtil::FileUtils::MakeDirectory ( const std::string &  strDir  )  const

creates a new directory from a path.

Parameters:
strDir the directory to create.
Exceptions:
FileExceptionEnum::FileNotFound if the parent path does not exist.
FileExceptionEnum::IOException if an error occurs creating the directory

bool dtUtil::FileUtils::DirExists ( const std::string &  strDir  )  const

Parameters:
strDir The directory to check.

Returns:
true if the path exists and is a directory

std::string dtUtil::FileUtils::RelativePath ( const std::string &  absolutePath,
const std::string &  file 
) const

Helper function that returns the relative path between absolutePath and file.

Parameters:
absolutePath The absolute path to search
file The absolute path to the file
Returns:
The relative path or empty string for failure
Note:
This function assumes that directory separaters are equal for both paths


Member Data Documentation

const char dtUtil::FileUtils::PATH_SEPARATOR = '/' [static]


http://www.delta3d.org
2.0.0 generated 14 Feb 2008