hi, i've been looking at this for awhile and i can't manage to see what i've done wrong. ..i have the following code i'm using to flatten a directory structure:
public ArrayList flatten(MyDir m) { ArrayList fl = new ArrayList(); if (m != null) { ArrayList mf = mdir.getFiles(); Iterator e = mf.iterator(); int cou = 0; while(e.hasNext()) { cou++; System.out.println("flatten:e.hasNext(): " + e.hasNext()); MyFile nxt = (MyFile)e.next(); System.out.println("" + cou + ".flatten,adding " + nxt.getPath()); fl.add(nxt); System.out.println("added."); System.out.println("flatten:e.hasNext(): " + e.hasNext()); } ArrayList md = mdir.getDirs(); e = md.iterator(); while (e.hasNext()) fl.addAll(flatten((MyDir)e.next())); } return fl }
the problem is when i hit an infinite loop in the first iterator loop, for the ArrayList mf's iterator, i get as output:
sorry, i figured this out, it was scope...i forgot to rename mdir to m when i changed the flatten() into a call to a helper function flatten(MyDir m), as flatten(mdir).
FYI, to avoid flattening the code in your post, you can use the java tags described in the "Formatting Your Post" sidebar, visible while you are composing it. So instead of stuff like this: class Ugly { private bool isUgly = true; public boolean ew() { if( this.isUgly ) return true; } } You get stuff like this: