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.
<?php
$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!!!]
}
}
?>
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.
<?php
$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!!!]
}
}
?>
Comment