01: package tide.utils;
02:
03: import snow.utils.storage.FileUtils;
04: import java.util.*;
05: import java.io.*;
06:
07: public final class FileUtilities {
08: private FileUtilities() {
09: }
10:
11: /** Not recurse !
12: * Used to detect ".jar" files in jre/lib
13: */
14: public static List<File> getAllFilesInDirEndingWithIgnoreCases(
15: final File dir, final String endLow) {
16: List<File> files = new ArrayList<File>();
17: if (dir.isFile()) {
18: if (dir.getName().toLowerCase().endsWith(endLow)) {
19: files.add(dir);
20: }
21: } else {
22: if (dir.exists()) {
23: for (File f : dir.listFiles()) {
24: if (f.getName().toLowerCase().endsWith(endLow)) {
25: files.add(f);
26: }
27: }
28: } else {
29: System.out.println("Not existing: " + dir);
30: }
31: }
32: return files;
33: }
34:
35: /** if dir is a directory, return the first level subdirectories (first level, NOT recurse).
36: */
37: public static List<File> getDirectories(File dir) {
38: List<File> files = new ArrayList<File>();
39: if (dir.isDirectory()) {
40: for (File f : dir.listFiles(FileUtils.folderFileNameFilter)) {
41: //if(f.isDirectory())
42: //{
43: files.add(f);
44: //}
45: }
46: }
47: return files;
48: }
49:
50: /** Root is included.
51: */
52: @tide.annotations.Recurse
53: public static void getAllDirectoriesRecurse_depthFirst(
54: final List<File> dirs, final File root) {
55: if (!root.isDirectory())
56: return;
57:
58: // recurse
59: for (final File dir : getDirectories(root)) {
60: getAllDirectoriesRecurse_depthFirst(dirs, dir);
61: }
62:
63: dirs.add(root);
64: }
65: }
|