Revision: 623
http://japi.svn.sourceforge.net/japi/?rev=623&view=rev
Author: christianhujer
Date: 2007-09-30 05:46:08 -0700 (Sun, 30 Sep 2007)
Log Message:
-----------
Added maximum depth and made printing the total optional.
Modified Paths:
--------------
tools/dircount/trunk/src/prj/net/sf/japi/dircount/DirCount.java
tools/dircount/trunk/src/prj/net/sf/japi/dircount/DirCount.properties
Modified: tools/dircount/trunk/src/prj/net/sf/japi/dircount/DirCount.java
===================================================================
--- tools/dircount/trunk/src/prj/net/sf/japi/dircount/DirCount.java 2007-09-30 11:49:23 UTC (rev 622)
+++ tools/dircount/trunk/src/prj/net/sf/japi/dircount/DirCount.java 2007-09-30 12:46:08 UTC (rev 623)
@@ -5,6 +5,7 @@
import java.util.List;
import net.sf.japi.io.args.ArgParser;
import net.sf.japi.io.args.LogCommand;
+import net.sf.japi.io.args.Option;
import org.jetbrains.annotations.NotNull;
/**
@@ -21,6 +22,21 @@
}
};
+ /** The default maximum depth. */
+ private static final int DEFAULT_MAX_DEPTH = -1;
+
+ /** The maximum depth to scan. */
+ private int maxDepth = DEFAULT_MAX_DEPTH;
+
+ /** The current depth in the scan. */
+ private int depth = 0;
+
+ /** The default whether to print the total. */
+ private static final boolean DEFAULT_PRINT_TOTAL = true;
+
+ /** Whether to print the total. */
+ private boolean printTotal = DEFAULT_PRINT_TOTAL;
+
/** Main program.
* @param args Command line arguments (try --help).
*/
@@ -28,16 +44,34 @@
ArgParser.simpleParseAndRun(new DirCount(), args);
}
+ /** Sets the maximum depth for printouts while scanning.
+ * @param maxDepth Maximum depth for printouts while scanning.
+ */
+ @Option("maxDepth")
+ public void setMaxDepth(@NotNull final Integer maxDepth) {
+ this.maxDepth = maxDepth;
+ }
+
+ /** Sets whether to print the total.
+ * @param printTotal <code>true</code> if the total should be printed, otherwise <code>false</code>.
+ */
+ @Option("printTotal")
+ public void setPrintTotal(@NotNull final Boolean printTotal) {
+ this.printTotal = printTotal;
+ }
+
/** {@inheritDoc} */
@SuppressWarnings({"InstanceMethodNamingConvention"})
public int run(@NotNull final List<String> args) throws Exception {
+ int sum = 0;
if (args.size() == 0) {
- count(".");
+ sum += count(".");
} else {
- int sum = 0;
for (final String dir : args) {
sum += count(dir);
}
+ }
+ if (printTotal) {
System.out.println("Total: " + sum);
}
return 0;
@@ -63,10 +97,14 @@
int count = 0;
final File[] subDirs = dir.listFiles(DIR_FILTER);
for (final File subDir : subDirs) {
+ depth++;
count += count(subDir);
+ depth--;
}
count += dir.listFiles().length;
- System.out.println(dir + ": " + count);
+ if (depth < (maxDepth & 0xFFFFFFFFl)) {
+ System.out.println(dir + ": " + count);
+ }
return count;
}
Modified: tools/dircount/trunk/src/prj/net/sf/japi/dircount/DirCount.properties
===================================================================
--- tools/dircount/trunk/src/prj/net/sf/japi/dircount/DirCount.properties 2007-09-30 11:49:23 UTC (rev 622)
+++ tools/dircount/trunk/src/prj/net/sf/japi/dircount/DirCount.properties 2007-09-30 12:46:08 UTC (rev 623)
@@ -2,3 +2,6 @@
# Copyright (c) 2007, Your Corporation. All Rights Reserved.
#
+helpHeader=Count the number of files and directories in a tree.
+setMaxDepth=Sets the maximum depth for which the sum should be printed.
+setPrintTotal=Sets whether the total should be printed (default: true).
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|