diff options
author | Andy Cedilnik <andy.cedilnik@kitware.com> | 2005-02-11 21:25:07 (GMT) |
---|---|---|
committer | Andy Cedilnik <andy.cedilnik@kitware.com> | 2005-02-11 21:25:07 (GMT) |
commit | 39fcca05cf2c61e0f70c47997670a107ce7c2ab8 (patch) | |
tree | 06583b757f8bae02eb2614523d2ff6cab12f8064 /Source/kwsys | |
parent | 71ff74d0459fe0fd08e51f79da8976d0b92786c0 (diff) | |
download | CMake-39fcca05cf2c61e0f70c47997670a107ce7c2ab8.zip CMake-39fcca05cf2c61e0f70c47997670a107ce7c2ab8.tar.gz CMake-39fcca05cf2c61e0f70c47997670a107ce7c2ab8.tar.bz2 |
ENH: Implement copy of directory with content
Diffstat (limited to 'Source/kwsys')
-rw-r--r-- | Source/kwsys/SystemTools.cxx | 45 | ||||
-rw-r--r-- | Source/kwsys/SystemTools.hxx.in | 3 |
2 files changed, 48 insertions, 0 deletions
diff --git a/Source/kwsys/SystemTools.cxx b/Source/kwsys/SystemTools.cxx index 023eae8..b9c385f 100644 --- a/Source/kwsys/SystemTools.cxx +++ b/Source/kwsys/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/Source/kwsys/SystemTools.hxx.in b/Source/kwsys/SystemTools.hxx.in index 4e042ff..eff12b4 100644 --- a/Source/kwsys/SystemTools.hxx.in +++ b/Source/kwsys/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); |