Backtracking through a directory.

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

I was wondering if there was a way to backtrack through a directory.
Let's say that we "readdir'd" our way through the directory to the end
and now would like to back up 3 files to read the third from the last.

Is there an easy way to do this or would I have to find the total
number of directory entries and then calculate exactly how many reads
it takes before getting to the desired location?

Any input would be appreciated.

$dir = '../zone16/misc';
if ( is_dir($dir) && ($dh = opendir($dir)) )
  while ( ($file = readdir($dh)) !== false )
    print $file.'<br>';
  if ( ($file = readdir($dh)) == false )
    [!!!back up 3 files and read the third to last file!!!]

Re: Backtracking through a directory.

Win wrote:
Quoted text here. Click to load it

Either that, or store the result of the successive readdir()s in an

Re: Backtracking through a directory.

Thanks for the input, Oli. :-)

Re: Backtracking through a directory.

The easiest way to work with file listing is glob(). /

Site Timeline