douqian3712 2013-08-27 20:21
浏览 8

不会删除所有带有'delete recursive dir'功能的文件

I try to delete a big directory with a lot of subfolders and files (>1000). There are many functions built for this purpose, I use the following:

function rrmdir($dir) {
        if (is_dir($dir)) {
            $objects = scandir($dir);
            foreach ($objects as $object) {
                if ($object != "." && $object != "..") {
                    if (filetype($dir . "/" . $object) == "dir"){
                        log_message(201,array(),'Try to delete folder: '.$dir.'/'.$object);
                        rrmdir($dir . "/" . $object);
                    }else{
                        log_message(201,array(),'Try to delete FILE: '.$dir.'/'.$object);
                        unlink($dir . "/" . $object);
                    }
                }
            }
            reset($objects);
            rmdir($dir);
        }
    }

The problem is, that many files are left behind. Is this usual behavior, are is something wrong with my code? If it is usual behavior, how can I get around this problem?

Thanks in advance.

  • 写回答

1条回答 默认 最新

  • douqian1517 2013-08-27 20:26
    关注

    Different Operating handles this different. At most OS an filesystems, files can be locked exclusive for read or write operations.

    If another process holds the file-handle with a lock, your process may not modify (or delete) the file. This may also be true for different threads.

    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器