source: release-kits/lirk3/ant-scripts/tasks/antelope/src/ise/antelope/tasks/typedefs/file/FileCount.java@ 14982

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

initial import of LiRK3

File size: 856 bytes
Line 
1package ise.antelope.tasks.typedefs.file;
2
3import java.io.*;
4
5/**
6 * Copyright 2003
7 *
8 * @version $Revision: 1.1 $
9 */
10public class FileCount implements FileOp {
11
12 /**
13 * Counts the number of files in a directory. Does not recurse. Does not
14 * count subdirectores. Only counts files in the directory.
15 *
16 * @param f a directory
17 * @return the number of files contained in the directory.
18 */
19 public String execute(File f) {
20 if (f == null)
21 throw new IllegalArgumentException("file cannot be null");
22 if (!f.isDirectory())
23 return "1";
24 File[] files = f.listFiles();
25 int file_count = 0;
26 for (int i = 0; i < files.length; i++) {
27 if (files[i].isFile())
28 ++file_count;
29 }
30 return String.valueOf(file_count);
31 }
32}
33
34
Note: See TracBrowser for help on using the repository browser.