Java iterating through all the files and only the unique RAR archives in a directory
<p>How can I iterate over over all the RAR archives in a directory. I know how to iterate over the files in a directory but I'm only interested in RAR archives. If they were simple RAR archives with the extension <code>.rar</code> it wouldn't be an issue but my directories can have multiple spanned archives and I only want the first/main volume in the set. I also would like to have the other files in the directory:</p>

<p>Here are the contents of a sample directory:</p>

<ul>
<li><code>file.txt</code></li>
<li><code>somefile.zip</code></li>
<li><code>hello.rar</code></li>
<li><code>test.part1.rar</code></li>
<li><code>test.part2.rar</code></li>
<li><code>example.rar</code></li>
<li><code>example.r00</code></li>
</ul>

<p>Result:</p>

<ul>
<li><code>file.txt</code></li>
<li><code>somefile.zip</code></li>
<li><code>hello.rar</code></li>
<li><code>test.part1.rar</code></li>
<li><code>example.rar</code></li>
</ul>

<p>This is what I'm using ti iterate over the directory:</p>

<pre><code>  import java.io.File;

  ...

  for (File child : (new File(myDirectoryPath)).listFiles()) {
    if (!child.isDirectory()) {
      //Do something with the file
    }
  }
</code></pre>

<p>How can I do this? I need to detect whether it is a RAR archive or not. If it isn't, use it. If it is, I'd need to check whether it is the first part of an archive. if yes, do whatever, else ignore it.</p>

<p>Thanks</p>
