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 .rar
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:
Here are the contents of a sample directory:
file.txt
somefile.zip
hello.rar
test.part1.rar
test.part2.rar
example.rar
example.r00
Result:
file.txt
somefile.zip
hello.rar
test.part1.rar
example.rar
This is what I'm using ti iterate over the directory:
import java.io.File;
...
for (File child : (new File(myDirectoryPath)).listFiles()) {
if (!child.isDirectory()) {
//Do something with the file
}
}
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.
Thanks