KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > uni_hamburg > eggink > autojar > FileExpand


1 package de.uni_hamburg.eggink.autojar;
2
3 /* This program is free software; you can redistribute it and/or
4  * modify it under the terms of the GNU General Public License
5  * as published by the Free Software Foundation; either version 2
6  * of the License, or (at your option) any later version.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16  *
17  * Bernd.Eggink@rrz.uni-hamburg.de
18  */

19
20 import java.io.*;
21 import java.util.*;
22
23 /** Expand wildcards in file names
24  *
25  * @author Bernd Eggink, RRZ Uni Hamburg (Bernd.Eggink@rrz.uni-hamburg.de)
26  *
27  */

28
29 public class FileExpand
30 {
31     private FileExpand()
32     { }
33
34     //----------------------------------------------------------------------
35

36     /** Get List of files matching a wildcard expression, relative to basedir
37      *
38      * @param basedir Directory part, may be null.
39      * @param expr relative path, last component may contain wildcards
40      * @return Array of matching file names
41      */

42
43     static public String JavaDoc[] getList(File basedir, String JavaDoc expr)
44     {
45         try
46         {
47             File exprFile = new File(expr),
48                  dir = new File(basedir, expr);
49
50             dir = dir.getAbsoluteFile().getParentFile();
51
52             if (! dir.exists())
53                 return null;
54
55             String JavaDoc[] names = dir.list(new OSFilter(exprFile.getName()));
56             String JavaDoc base = exprFile.getParent(); // Base of expr part, may be null
57

58             if (base != null)
59             {
60                 base += File.separator;
61
62                 for (int i = 0; i < names.length; ++i)
63                     names[i] = base + names[i];
64             }
65
66             return names;
67         }
68         catch (Exception JavaDoc ex)
69         {
70             System.err.println(ex);
71             return null;
72         }
73     }
74 }
75
Popular Tags