Let's say I have a folder containing 99tf.txt, 40.txt, 65.txt , in any order
If the current script var is 40.txt: I would like it to delete 65.txt (or the next file)
I was looking into something like that:
$file='40.txt';
if ($handle = opendir('./log/')) {
$entry= readdir($handle);
//move pointer to 40.txt
while ($file != $entry && $entry !== false) {
$entry = readdir($handle)
}
//go to the next file
$entry = readdir($handle)
if(is_file('./log/'.$entry)){
unlink('./log/'.$entry);
}
}
But I would like to avoid to go into a loop each time since there could be a lot of files in the folder. So is there a way to change the $handle pointer to the '$file' directly and delete the next file?