Note that there are some explanatory texts on larger screens.

plurals
  1. POJava: how to get all subdirs recursively?
    text
    copied!<p>Before debugging the late-hour-out-of-bound-recursive-function: is there a command to get subdirs? <code>giveMeSubDirs(downToPath)</code>?</p> <pre><code>// WARNING: RECURSION out of bound or too much data public HashSet&lt;FileObject&gt; getAllDirs(String path) { HashSet&lt;FileObject&gt; checkedDirs = new HashSet&lt;FileObject&gt;(); HashSet&lt;FileObject&gt; allDirs = new HashSet&lt;FileObject&gt;(); String startingPath = path; File fileThing = new File(path); FileObject fileObject = new FileObject(fileThing); for (FileObject dir : getDirsInDir(path)) { // SUBDIR while ( !checkedDirs.contains(dir) &amp;&amp; !(getDirsInDir(dir.getFile().getParent()).size() == 0)) { // DO NOT CHECK TOP DIRS if any bottom dir UNCHECKED! while ( uncheckedDirsOnLevel(path, checkedDirs).size() &gt; 0) { while (getDirsInDir(path).size() == 0 || (numberOfCheckedDirsOnLevel(path, checkedDirs)==getDirsInDir(path).size())) { allDirs.add(new FileObject(new File(path))); checkedDirs.add(new FileObject(new File(path))); if(traverseDownOneLevel(path) == startingPath ) return allDirs; //get nearer to the root path = traverseDownOneLevel(path); } path = giveAnUncheckedDir(path, checkedDirs); if ( path == "NoUnchecked.") { checkedDirs.add(new FileObject( (new File(path)).getParentFile() )); break; } } } } return allDirs; } </code></pre> <p><strong>Summary about the code:</strong></p> <ol> <li>Go as deep to the directory tree as possible. When there is no dir in a dir, stop, put the dir to the set, traverse up. Do not check dirs in the set. </li> <li>Stop and return the set if you reach the starting path.</li> <li>Repeat steps 1 and 2.</li> </ol> <p>PREMISE: the directory-structure is finite and with a small data amount.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload