I have recently been struggling with removal of symlinked folders with content on windows in PHP.
The process I am doing is: 1. symlink files/folders from location A to location B (all good) 2. unlink all files/folders from location B
Now this is where things get tricky. My code:
echo("\n unlinking: ".$pre.$folder.'/'.$elem);
if(file_exists($pre.$folder.'/'.$elem)){
if(isWindows()){
if(is_dir($pre.$folder.'/'.$elem)){
rmdir($pre.$folder.'/'.$elem);
} else {
unlink($pre.$folder.'/'.$elem);
}
} else {
unlink($pre.$folder.'/'.$elem);
}
} else {
echo("\n -> Not there. \n");
}
Everything works properly if the target is a file or an empty folder. When the symlinked folder has contents however, I get a warning that I can't remove a non-empty folder and the folder is not removed.
Warning: rmdir(dirname): Directory not empty
Which means that a symlinked folder with contents on windows is non-removable when using rmdir(the recommended operation).
I can remove that folder manually in windows explorer and that works properly(removes a symlink only).
Would appreciate help, Sivael.
Found out what was going on.
It turns out that it was not PHP related after all - those folders were under version control in TortoiseSVN and NetBeans, which happened to mess with the symlinks somehow.
Can't replicate the behaviour now.
Thanks:)