KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > compiler > batch > FileFinder


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.internal.compiler.batch;
12
13 import java.io.File JavaDoc;
14 import java.util.ArrayList JavaDoc;
15
16 public class FileFinder {
17     
18 public static String JavaDoc[] find(File JavaDoc f, String JavaDoc pattern) {
19     ArrayList JavaDoc files = new ArrayList JavaDoc();
20     find0(f, pattern, files);
21     String JavaDoc[] result = new String JavaDoc[files.size()];
22     files.toArray(result);
23     return result;
24 }
25 private static void find0(File JavaDoc f, String JavaDoc pattern, ArrayList JavaDoc collector) {
26     if (f.isDirectory()) {
27         String JavaDoc[] files = f.list();
28         if (files == null) return;
29         for (int i = 0, max = files.length; i < max; i++) {
30             File JavaDoc current = new File JavaDoc(f, files[i]);
31             if (current.isDirectory()) {
32                 find0(current, pattern, collector);
33             } else {
34                 if (current.getName().toUpperCase().endsWith(pattern)) {
35                     collector.add(current.getAbsolutePath());
36                 }
37             }
38         }
39     }
40 }
41 }
42
Popular Tags