---------------------------------------------------------------------------
| 179 | |
| 180 | //--------------------------------------------------------------------------- |
| 181 | bool copyDirectory( |
| 182 | const std::string &source, |
| 183 | const std::string &target, |
| 184 | const std::string &name, |
| 185 | bool recurse, |
| 186 | bool overwrite, |
| 187 | bool copyAttributes) |
| 188 | { |
| 189 | //Check source |
| 190 | if (!dirExists(source)) |
| 191 | return false; |
| 192 | |
| 193 | //Check target |
| 194 | if (!dirExists(target)) |
| 195 | { |
| 196 | if (!createDirectory(target)) |
| 197 | { |
| 198 | return false; |
| 199 | } |
| 200 | } |
| 201 | else if (!overwrite) |
| 202 | { |
| 203 | if (!emptyDir(target)) |
| 204 | return false; |
| 205 | } |
| 206 | |
| 207 | |
| 208 | //Get source files |
| 209 | std::vector<std::string> files; |
| 210 | getFiles(source, name, files, recurse); |
| 211 | |
| 212 | if (files.empty()) |
| 213 | return true; |
| 214 | |
| 215 | //Copy files |
| 216 | std::string sourceFile, targetFile; |
| 217 | const size_t sourceSize = source.size(); |
| 218 | |
| 219 | for (std::vector<std::string>::iterator iter = files.begin(); iter != files.end(); ++iter) |
| 220 | { |
| 221 | sourceFile = (*iter); |
| 222 | targetFile = target + sourceFile.substr(sourceSize, (*iter).size()); |
| 223 | if (!copyFile(sourceFile, targetFile, overwrite, copyAttributes)) |
| 224 | return false; |
| 225 | } |
| 226 | |
| 227 | return true; |
| 228 | |
| 229 | } |
| 230 | |
| 231 | |
| 232 |