I'm afraid I still don't understand the need for the extra checking. If you have a name, say "img_2678.jpg", in the DB that you want to delete from the directory ../../pics, you'd just create the proper path and do
unlink "../../pics/img_2678.jpg";
The OS will then try to locate the physical file and, if it's there, delete it. If it's not there, the unlink call will fail. That's it. No need to first figure out if the directory holds a file img_2678.jpg.
Or is it that you don't know which directory holds the files? In this case, just check the return value of the unlink call. If it succeeded, you likely picked the right one, otherwise try the next directory candidate.
(The same general considerations would apply if you're actually going to move the files, instead of deleting them.)
|