01: /*
02: * Created on Oct 4, 2005
03: */
04: package uk.org.ponder.fileutil;
05:
06: import java.io.File;
07: import java.io.IOException;
08:
09: import uk.org.ponder.stringutil.StringList;
10: import uk.org.ponder.util.UniversalRuntimeException;
11:
12: public class FileUtil {
13: public static int FILE_MASK = 1;
14: public static int DIRECTORY_MASK = 2;
15:
16: static public StringList getListing(File aStartingDir, int mask) {
17: StringList result = new StringList();
18:
19: File[] filesAndDirs = aStartingDir.listFiles();
20: if (filesAndDirs == null) {
21: return result;
22: }
23:
24: for (int i = 0; i < filesAndDirs.length; ++i) {
25: File file = filesAndDirs[i];
26: if (!file.isFile()) {
27: if ((mask & DIRECTORY_MASK) != 0) {
28: result.add(file.toString());
29: }
30: StringList deeperList = getListing(file, mask);
31: result.addAll(deeperList);
32: } else {
33: if ((mask & FILE_MASK) != 0) {
34: result.add(file.toString());
35: }
36: }
37:
38: }
39: //Collections.sort(result);
40: return result;
41: }
42:
43: public static final String getCanonicalPath(String path) {
44: File f = new File(path);
45: try {
46: return f.getCanonicalPath();
47: } catch (IOException e) {
48: throw UniversalRuntimeException.accumulate(e,
49: "Unable to convert " + path
50: + " to a canonical path");
51: }
52: }
53: }
|