Annoying DirectoryIterator problem
Posted: Fri Apr 01, 2011 8:02 am
I have spent ages tracking down a problem to my DirectoryIterator usage.
I want to delete a directory so am first using DirectoryIterator to check if the directory contains any files, and if it does, I delete them and then try to delete the directory.
The trouble is, the rmdir command errors with a "permission denied" message. However if I don't include the line
$files = new DirectoryIterator($image_dir);
then I can go an delete the directory no problem.
Its as if the DirectoryIterator is hogging the directory so I can't delete it. Anyone know how to force the iterator to realease the directory? I am working in WIndows and have already tried closedir(opendir($image_dir)) before rmdir($image_dir) but it makes no different.
Thanks.
I want to delete a directory so am first using DirectoryIterator to check if the directory contains any files, and if it does, I delete them and then try to delete the directory.
The trouble is, the rmdir command errors with a "permission denied" message. However if I don't include the line
$files = new DirectoryIterator($image_dir);
then I can go an delete the directory no problem.
Its as if the DirectoryIterator is hogging the directory so I can't delete it. Anyone know how to force the iterator to realease the directory? I am working in WIndows and have already tried closedir(opendir($image_dir)) before rmdir($image_dir) but it makes no different.
Thanks.