Accessing files in directory using an index number

When accessing files in a directory, is it possible to access each file using an index number?
To make it clear, here is the example Im working on (below). You see the while loop is just one piece, it keeps checking if there are anymore files. Is there a cleaner way to do this, using some kind of index number to represent each file, etc?
My objective is to break this while loop say every 10 loops, and then resume later on (using a redirect) since it times out … so I want to keep track with where I’ve reached.

 
$dirInput = opendir($inputFolder);
if(!$dirInput) return 0;
while (($filename = readdir($dirInput))) {
 //process the file
}