Commits

mquigley committed 8f5736f

Rather than simply deciding if we want to recursively iterate or not, let's use a maximum depth.

  • Participants
  • Parent commits 7a0d40f
  • Branches Dev_0.0.3

Comments (0)

Files changed (1)

File src/main/java/com/quigley/filesystem/FilesystemIterator.java

     }
 
     public void iterate(FilesystemPath path) throws FilesystemException {
-    	iterate(path, true);
+    	iterate(path, 0, -1);
     }
     
-    public void iterate(FilesystemPath path, boolean recursive) throws FilesystemException {
+    public void iterate(FilesystemPath path, int maxDepth) {
+    	iterate(path, 0, maxDepth);
+    }
+    
+    private void iterate(FilesystemPath path, int currentDepth, int maxDepth) throws FilesystemException {
     	File pathF = path.asFile();
     	if(pathF.exists() && pathF.canRead()) {
     		visit(path);
     			File[] contents = pathF.listFiles();
     			for(File f : contents) {
     				FilesystemPath fPath = new FilesystemPath(path).add(f.getName());
-    				if(recursive) {
-    					iterate(fPath, recursive);
+    				if(currentDepth < maxDepth || maxDepth == -1) {
+    					iterate(fPath, currentDepth + 1, maxDepth);
     				} else {
     					visit(fPath);
     				}