Browse Source

Implemented FileOps::moveFile.


git-svn-id: https://svn.microneil.com/svn/CodeDweller/branches/adeniz_1@90 d34b734f-a00e-4b39-a726-e4eeb87269ab
adeniz_1
adeniz 9 years ago
parent
commit
97d91cbab4
2 changed files with 34 additions and 0 deletions
  1. 16
    0
      filesystem.cpp
  2. 18
    0
      filesystem.hpp

+ 16
- 0
filesystem.cpp View File

#include <unistd.h> #include <unistd.h>
#include <sys/types.h> #include <sys/types.h>
#include <cstdio>
#include <cstdlib> #include <cstdlib>
#include <cstring> #include <cstring>
#include <cerrno> #include <cerrno>
namespace CodeDweller { namespace CodeDweller {
void FileOps::moveFile(std::string const &from, std::string const &to) {
#ifdef _WIN32
if (MoveFile(from.c_str(), to.c_str()) == 0) {
#else
if (rename(from.c_str(), to.c_str()) != 0) {
#endif
throw std::runtime_error("Error moving file \"" + from +
"\" to file \"" + to + "\": " +
FileReference::getErrorText());
}
}
#ifdef _WIN32 #ifdef _WIN32
char const FilePath::DirectorySeparator = '\\'; char const FilePath::DirectorySeparator = '\\';
#else #else

+ 18
- 0
filesystem.hpp View File



namespace CodeDweller { namespace CodeDweller {


/** Abstracts OS specifics for manipulating files. */
class FileOps {

public:

/** Move a file.

@param[in] from is the path of the file to move.

@param[in] to is the path the move the file to.

@throws std::runtime_error if an error occurs.

*/
static void moveFile(std::string const &from, std::string const &to);

};

/** Abstracts OS specifics for manipulating file paths. */ /** Abstracts OS specifics for manipulating file paths. */
class FilePath { class FilePath {



Loading…
Cancel
Save