Posted By:
David_Bates
Posted On:
Friday, March 14, 2003 07:16 AM
I'm not even going to ask why you have 10 million files in a directory! However, I've knocked up a little script that I think you could probably alter to do what you are trying to achieve. Basically, I'm creating my own FileFilter that filters ranges. This will allow you to get the first 500 files, then the next 500 and so on. This allows you to work piece-wise through the directory listing. I haven't tried this out on a million files (I love my harddrive too much), but I'd be really interested to find out if this works.
Cheers,
David.
PS - ...or just use Perl... ;-)
import java.io.*;
public class Filtering {
public static void main(String[] args) {
Filtering f = new Filtering();
System.out.print(f.getListing());
}
public String getListing() {
String returnString = "";
RangeFilter rf = new RangeFilter(2, 3);
File f = new File("..");
File listing[] = f.listFiles(rf);
for (int i=0; i returnString += listing[i].getName() + "
";
}
return returnString;
}
public class RangeFilter implements FileFilter {
private int startRange;
private int endRange;
private int currentIndex;
public RangeFilter(int startRange, int endRange) {
this.startRange = startRange;
this.endRange = endRange;
currentIndex = 0;
}
public boolean accept(File f) {
currentIndex++;
if (currentIndex >= startRange && currentIndex <= endRange) {
return true;
}
else {
return false;
}
}
}
}