01: /* DDSteps - Data Driven JUnit Test Steps
02: * Copyright (C) 2006 Jayway AB
03: *
04: * This library is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License version 2.1 as published by the Free Software Foundation.
07: *
08: * This library is distributed in the hope that it will be useful,
09: * but WITHOUT ANY WARRANTY; without even the implied warranty of
10: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11: * Lesser General Public License for more details.
12: *
13: * You should have received a copy of the GNU Lesser General Public
14: * License along with this library; if not, visit
15: * http://www.opensource.org/licenses/lgpl-license.php
16: */
17: package org.ddsteps.util;
18:
19: import java.io.File;
20:
21: /**
22: * @author adamskogman
23: *
24: */
25: public class FileUtils {
26:
27: /**
28: * Delete all files in a tree.
29: * <p>
30: * TODO: Refactor to utils.
31: *
32: * @param file
33: * File or dir
34: * @return True if deleted
35: */
36: public static boolean delTree(File file) {
37:
38: boolean status = true;
39:
40: if (file.isDirectory()) {
41:
42: // Delete all children
43: File[] children = file.listFiles();
44:
45: for (int i = 0; i < children.length; i++) {
46: File child = children[i];
47: // recursive - wheeee!
48: status &= delTree(child);
49: }
50:
51: }
52:
53: // Delete file or empty dir
54: status &= file.delete();
55:
56: return status;
57: }
58:
59: }
|