01: package org.acm.seguin.pmd.cpd;
02:
03: import java.io.File;
04: import java.io.FilenameFilter;
05: import java.util.ArrayList;
06: import java.util.List;
07:
08: public class FileFinder {
09:
10: private FilenameFilter filter;
11: private static final String FILE_SEP = System
12: .getProperty("file.separator");
13:
14: public List findFilesFrom(String dir, FilenameFilter filter,
15: boolean recurse) {
16: this .filter = filter;
17: List files = new ArrayList();
18: scanDirectory(new File(dir), files, recurse);
19: return files;
20: }
21:
22: /**
23: * Implements a tail recursive file scanner
24: */
25: private void scanDirectory(File dir, List list, boolean recurse) {
26: String[] candidates = dir.list(filter);
27: for (int i = 0; i < candidates.length; i++) {
28: File tmp = new File(dir + FILE_SEP + candidates[i]);
29: if (tmp.isDirectory()) {
30: if (recurse) {
31: scanDirectory(tmp, list, true);
32: }
33: } else {
34: list.add(new File(dir + FILE_SEP + candidates[i]));
35: }
36: }
37: }
38: }
|