Java, searching through folders to match a name
<p><br>
I am using Java to search for a file or folder that matches a specific case. For instance I want to search through all the files and folders and iterate through them as many times as necessary until I find a result. </p>

<h3>The catch</h3>

<p>I am searching for files and folders through a binary image of a file system. This means I doubt there are any preexisting classes such <code>java.file.*</code> to do it for me. If it helps, I can tell you that I can tell the difference between files and folders easily enough. (a folder is flagged as 0x20)</p>

<p>The only way I can think of is to do a standard loop and iterate several times, but this limits me if a file or folder is several folders deep.</p>

<p>All input greatly welcome</p>

<h3>Edit</h3>

<p>Just to clarify, I'm using a binary image and searching though it for directories.</p>

<p>I think the term "directory" could be misleading. Given an initial vaule of 0 I want to examine a series of bytes. If in the correct place I encounter a 0x20 (directory marker), I need to jump to a new location in the binary image and start searching again. If I encounter 0x20 again, I need to jump and start again; when finished I return to the point I was and continue to search for another 0x20. I need to do this until I have no more 0x20's in specific spots.</p>

<p>I can do this using <em>n</em> loops but that will only take me <em>n</em> directorys deep. I am wondering if anyone has any ideas on how to do this until there are no more directory markers.</p>

<p>Not really sure if this clarifies things but I hope it does.</p>

<hr>

<p>EDIT
This is code that I'm using and im getting a stack overflow error. any ideas on how i can improve it?</p>

<pre><code>  public boolean isDirectory(int dirAttr)
{
    if (dirAttr == dir.ATTR_DIRECTORY)
        return true;
    else return false;
}
public void searchDirectory(int clusterNum, String name)
{
    for (int i = 0; i&lt;32;i++)
    {
        if(dir.DIR_NameS(clusterNum, i).contains(name))
        {
            System.out.println("Found a Match");
            System.out.println("File name = " + dir.DIR_NameS(clusterNum, i));
            System.out.println("File size in bytes = "+dir.DIR_FileSize(clusterNum, i));
            System.out.println("File starting cluster = "+dir.DIR_FstClusLO(clusterNum, i));
            System.out.println();
        }
        if(this.isDirectory(dir.DIR_Attr(clusterNum, i)))
        {
            searchDirectory(dir.DIR_FstClusLO(clusterNum, i), name);
        }
    }
}
</code></pre>
