diff --git a/SystemTools.cxx b/SystemTools.cxx index 5e4399fe223ade45ce178e11650f50c09306ec57..6c321c904d5a5451a7e7d09cdb35dd625dc4810d 100644 --- a/SystemTools.cxx +++ b/SystemTools.cxx @@ -1061,6 +1061,51 @@ bool SystemTools::CopyFileAlways(const char* source, const char* destination) return true; } +/** + * Copy a directory content from "source" directory to the directory named by + * "destination". + */ +bool SystemTools::CopyADirectory(const char* source, const char* destination) +{ + Directory dir; + dir.Load(source); + size_t fileNum; + if ( !SystemTools::MakeDirectory(destination) ) + { + return false; + } + for (fileNum = 0; fileNum < dir.GetNumberOfFiles(); ++fileNum) + { + if (strcmp(dir.GetFile(static_cast<unsigned long>(fileNum)),".") && + strcmp(dir.GetFile(static_cast<unsigned long>(fileNum)),"..")) + { + kwsys_stl::string fullPath = source; + fullPath += "/"; + fullPath += dir.GetFile(static_cast<unsigned long>(fileNum)); + if(SystemTools::FileIsDirectory(fullPath.c_str())) + { + kwsys_stl::string fullDestPath = destination; + fullDestPath += "/"; + fullDestPath += dir.GetFile(static_cast<unsigned long>(fileNum)); + if (!SystemTools::CopyADirectory(fullPath.c_str(), fullDestPath.c_str())) + { + return false; + } + } + else + { + if(!SystemTools::CopyFileAlways(fullPath.c_str(), destination)) + { + return false; + } + } + } + } + + return true; +} + + // return size of file; also returns zero if no file exists unsigned long SystemTools::FileLength(const char* filename) { diff --git a/SystemTools.hxx.in b/SystemTools.hxx.in index 2a5a363c4c3b4cf6848d2da68446fef5cfcc6c52..f5dd75ca0b05e26d87e92b639dcca0a8c65e30ed 100644 --- a/SystemTools.hxx.in +++ b/SystemTools.hxx.in @@ -172,6 +172,9 @@ public: ///! Copy a file. static bool CopyFileAlways(const char* source, const char* destination); + + ///! Copy content directory to another directory with all files and subdirectories + static bool CopyADirectory(const char* source, const char* destination); ///! Remove a file. static bool RemoveFile(const char* source);