#include <fileutils.h>
Public Member Functions | ||||
| bool | FileExists (const std::string &strFile) const | |||
| ||||
| 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 | |||
| ||||
| 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 | |||
| ||||
| 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 | |||
| ||||
| 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 | |||
| ||||
| 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 FileUtils & | GetInstance () | |||
| Character separating the parts of a file path. | ||||
Static Public Attributes | ||||
| static const char | PATH_SEPARATOR = '/' | |||
| static FileUtils& dtUtil::FileUtils::GetInstance | ( | void | ) | [inline, static] |
Character separating the parts of a file path.
| bool dtUtil::FileUtils::FileExists | ( | const std::string & | strFile | ) | const |
| strFile | the path to the file to check. |
| void dtUtil::FileUtils::FileCopy | ( | const std::string & | strSrc, | |
| const std::string & | strDest, | |||
| bool | bOverwrite | |||
| ) | const |
Copys a file.
| 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. |
| 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.
| 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. |
| 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.
| strFile | the path to the file to delete |
| FileExceptionEnum::IOException | if an error occurs deleting the data |
| struct FileInfo dtUtil::FileUtils::GetFileInfo | ( | const std::string & | strFile | ) | const [read] |
| 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.
popDirectory
| path | The path to the new directory. |
| FileExceptionEnum::FileNotFound | if the path does not exist. |
| const std::string & dtUtil::FileUtils::CurrentDirectory | ( | ) | const |
| 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.
| path | The path to the new directory. |
| FileExceptionEnum::FileNotFound | if the path does not exist. |
| void dtUtil::FileUtils::PopDirectory | ( | ) |
sets the current directory to the last directory on the stack.
| 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.
| relativePath | the relative path to convert to absolute. |
| FileExceptionEnum::FileNotFound | if the path does not exist. |
| DirectoryContents dtUtil::FileUtils::DirGetFiles | ( | const std::string & | path | ) | const |
Note: throws exceptions of type dtUtil::Exception.
| path | the path to the directory to list the contents of. |
| 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 |
| path | the path to the directory to get the subdirectories for. |
| 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.
| 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 |
| 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.
| strDir | The path of the directory to delete. | |
| bRecursive | true if the directory should be deleted recursively. |
| 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.
| strDir | the directory to create. |
| 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 |
| strDir | The directory to check. |
| 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.
| absolutePath | The absolute path to search | |
| file | The absolute path to the file |
const char dtUtil::FileUtils::PATH_SEPARATOR = '/' [static] |