1 | /* |
2 | * Created on Sep 13, 2004 |
3 | * |
4 | * TODO To change the template for this generated file go to |
5 | * Window - Preferences - Java - Code Style - Code Templates |
6 | */ |
7 | package biz.xsoftware.buildtemplate.test; |
8 | |
9 | import java.io.File; |
10 | import java.io.IOException; |
11 | import java.util.logging.Logger; |
12 | |
13 | /** |
14 | * @author Dean Hiller |
15 | * |
16 | * TODO To change the template for this generated type comment go to |
17 | * Window - Preferences - Java - Code Style - Code Templates |
18 | */ |
19 | public class Util { |
20 | |
21 | public final static Logger log = Logger.getLogger(Util.class.getName()); |
22 | |
23 | public static boolean removeDir(File d) { |
24 | log.finest("starting("+d.getAbsolutePath()+")"); |
25 | |
26 | String[] list = d.list(); |
27 | if (list == null) list = new String[0]; |
28 | log.finest("numFiles in directory=" + list.length); |
29 | for (int i = 0; i < list.length; i++) |
30 | { |
31 | String s = list[i]; |
32 | File f = new File(d, s); |
33 | if (f.isDirectory()) |
34 | { |
35 | if(!removeDir(f)) |
36 | return false; |
37 | } |
38 | else |
39 | { |
40 | log.finest("remove file="+f.getAbsolutePath()); |
41 | if (!f.delete()) |
42 | { |
43 | log.finest("FAILED because file " + f.getAbsolutePath()); |
44 | return false; |
45 | } |
46 | } |
47 | } |
48 | log.finest("remove directory="+d.getAbsolutePath()); |
49 | if (!d.delete()) |
50 | { |
51 | log.finest("FAILED because directory " + d.getAbsolutePath()); |
52 | return false; |
53 | } |
54 | log.finest("succeeded("+d.getAbsolutePath()+")"); |
55 | return true; |
56 | } |
57 | |
58 | public static String getAvailableFileName(File directory, String prefix) throws IOException { |
59 | File temp = File.createTempFile(prefix+"-", "", directory); |
60 | String path = temp.getAbsolutePath(); |
61 | temp.delete(); |
62 | return path; |
63 | } |
64 | |
65 | } |