Deletes the given file or directory if it exists, then creates a fresh directory in its place.
(File dirToRemove)
| 264 | |
| 265 | /** Deletes the given file or directory if it exists, then creates a fresh directory in its place. */ |
| 266 | public static void cleanDir(File dirToRemove) throws IOException { |
| 267 | if (dirToRemove.isFile()) { |
| 268 | FileMisc.forceDelete(dirToRemove); |
| 269 | } else if (dirToRemove.isDirectory()) { |
| 270 | try { |
| 271 | FileUtils.deleteDirectory(dirToRemove); |
| 272 | } catch (IOException e) { |
| 273 | // we couldn't delete the directory, |
| 274 | // but deleting everything inside is just as good |
| 275 | for (File file : FileMisc.list(dirToRemove)) { |
| 276 | FileMisc.forceDelete(file); |
| 277 | } |
| 278 | } |
| 279 | } |
| 280 | mkdirs(dirToRemove); |
| 281 | } |
| 282 | |
| 283 | /** |
| 284 | * Flattens a single directory (moves its children to be its peers, then deletes the given directory. |