Copy a folder from one place to another. This ignores all dot files and folders found in the source directory, to avoid copying silly .DS_Store files and potentially troublesome .svn folders.
(File sourceDir,
File targetDir)
| 314 | * files and potentially troublesome .svn folders. |
| 315 | */ |
| 316 | static public void copyDir(File sourceDir, |
| 317 | File targetDir) throws IOException { |
| 318 | if (sourceDir.equals(targetDir)) { |
| 319 | final String urDum = "source and target directories are identical"; |
| 320 | throw new IllegalArgumentException(urDum); |
| 321 | } |
| 322 | if (!targetDir.exists() && !targetDir.mkdirs()) { |
| 323 | throw new IOException("Could not create " + targetDir); |
| 324 | } |
| 325 | String[] filenames = sourceDir.list(); |
| 326 | if (filenames != null) { |
| 327 | for (String filename : filenames) { |
| 328 | // Ignore dot files (.DS_Store), dot folders (.svn) while copying |
| 329 | if (filename.charAt(0) != '.') { |
| 330 | File source = new File(sourceDir, filename); |
| 331 | File target = new File(targetDir, filename); |
| 332 | if (source.isDirectory()) { |
| 333 | //target.mkdirs(); |
| 334 | copyDir(source, target); |
| 335 | //noinspection ResultOfMethodCallIgnored |
| 336 | target.setLastModified(source.lastModified()); |
| 337 | } else { |
| 338 | copyFile(source, target); |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | } else { |
| 343 | throw new IOException("Could not read " + sourceDir); |
| 344 | } |
| 345 | } |
| 346 | |
| 347 | |
| 348 | static public void copyDirNative(File sourceDir, |
no test coverage detected