Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- Backtracking through a directory.
May 26, 2005, 5:31 am
rate this thread
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 )
if ( ($file = readdir($dh)) == false )
[!!!back up 3 files and read the third to last file!!!]