* Copy a directory content from "source" directory to the directory named by * "destination". */
| 2645 | * "destination". |
| 2646 | */ |
| 2647 | Status SystemTools::CopyADirectory(std::string const& source, |
| 2648 | std::string const& destination, |
| 2649 | SystemTools::CopyWhen when) |
| 2650 | { |
| 2651 | Status status; |
| 2652 | Directory dir; |
| 2653 | status = dir.Load(source); |
| 2654 | if (!status.IsSuccess()) { |
| 2655 | return status; |
| 2656 | } |
| 2657 | status = SystemTools::MakeDirectory(destination); |
| 2658 | if (!status.IsSuccess()) { |
| 2659 | return status; |
| 2660 | } |
| 2661 | |
| 2662 | for (size_t fileNum = 0; fileNum < dir.GetNumberOfFiles(); ++fileNum) { |
| 2663 | if (strcmp(dir.GetFile(static_cast<unsigned long>(fileNum)), ".") != 0 && |
| 2664 | strcmp(dir.GetFile(static_cast<unsigned long>(fileNum)), "..") != 0) { |
| 2665 | std::string fullPath = source; |
| 2666 | fullPath += "/"; |
| 2667 | fullPath += dir.GetFile(static_cast<unsigned long>(fileNum)); |
| 2668 | if (SystemTools::FileIsDirectory(fullPath)) { |
| 2669 | std::string fullDestPath = destination; |
| 2670 | fullDestPath += "/"; |
| 2671 | fullDestPath += dir.GetFile(static_cast<unsigned long>(fileNum)); |
| 2672 | status = SystemTools::CopyADirectory(fullPath, fullDestPath, when); |
| 2673 | if (!status.IsSuccess()) { |
| 2674 | return status; |
| 2675 | } |
| 2676 | } else { |
| 2677 | status = SystemTools::CopyAFile(fullPath, destination, when); |
| 2678 | if (!status.IsSuccess()) { |
| 2679 | return status; |
| 2680 | } |
| 2681 | } |
| 2682 | } |
| 2683 | } |
| 2684 | |
| 2685 | return status; |
| 2686 | } |
| 2687 | |
| 2688 | Status SystemTools::CopyADirectory(std::string const& source, |
| 2689 | std::string const& destination, bool always) |