source: release-kits/wirk3/ant-scripts/tasks/antelope/src/ise/antelope/tasks/typedefs/file/FileList.java@ 15023

Last change on this file since 15023 was 15023, checked in by oranfry, 16 years ago

did the bulk of the work on wirk3

File size: 1.9 KB
Line 
1package ise.antelope.tasks.typedefs.file;
2
3import java.io.File;
4import java.util.*;
5
6/**
7 * Copyright 2003
8 *
9 * @version $Revision: 1.2 $
10 */
11public class FileList implements FileOp {
12
13 private String what = "files";
14 private String separator = ",";
15 private boolean includepath = true;
16
17 public void setSeparator(String s) {
18 if (s != null)
19 separator = s;
20 }
21
22 public void setIncludepath(boolean b) {
23 includepath = b;
24 }
25
26 public void setWhat(String s) {
27 if (s == null || s.equals("files")) {
28 what = "files";
29 return;
30 }
31 else if (s.equals("dirs")) {
32 what = "dirs";
33 return;
34 }
35 else if (s.equals("all")) {
36 what = "all";
37 return;
38 }
39 else
40 what = "files";
41 }
42
43 /**
44 * Lists the files in a directory. Does not recurse. Does not
45 * list subdirectores. Only lists files in the directory.
46 *
47 * @param f a directory
48 * @return a list of files contained in the directory.
49 */
50 public String execute(File f) {
51 if (f == null)
52 throw new IllegalArgumentException("file cannot be null");
53 if (!f.isDirectory())
54 return f.toString();
55 List files = Arrays.asList(f.listFiles());
56 StringBuffer value = new StringBuffer();
57 for (Iterator it = files.iterator(); it.hasNext(); ) {
58 File file = (File)it.next();
59 if ( (what.equals("files") && file.isFile()) ||
60 (what.equals("dirs" ) && file.isDirectory()) ||
61 (what.equals("all" )) ) {
62 String filename = includepath ? file.getAbsolutePath() : file.getName();
63 value.append(filename);
64 if (it.hasNext())
65 value.append(separator);
66 }
67 }
68 return value.toString();
69 }
70}
71
72
Note: See TracBrowser for help on using the repository browser.