简体   繁体   English

PHP Windows,符号链接文件夹的rmdir

[英]PHP Windows, rmdir of a symlinked folder

I have recently been struggling with removal of symlinked folders with content on windows in PHP. 最近,我一直在努力删除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 我正在执行的过程是:1.从位置A符号链接文件/文件夹到位置B(都很好)2.从位置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). 这意味着使用rmdir(建议的操作)时,无法删除Windows上具有内容的符号链接文件夹。

I can remove that folder manually in windows explorer and that works properly(removes a symlink only). 我可以在Windows资源管理器中手动删除该文件夹,并且该文件夹可以正常工作(仅删除符号链接)。

Would appreciate help, Sivael. Sivael,非常感谢您的帮助。

When deleting a symlink, you need to treat it as a file, not a directory. 删除符号链接时,需要将其视为文件而不是目录。 So, you need to use unlink, rather than rmdir! 因此,您需要使用unlink,而不是rmdir!

HTH :) HTH :)

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. 事实证明,这毕竟不是与PHP相关的-这些文件夹在TortoiseSVN和NetBeans中受版本控制,这恰好与符号链接发生了冲突。

Can't replicate the behaviour now. 现在无法复制行为。

Thanks:) 谢谢:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM