【问题标题】:Directory is empty but laravel does not erase it, throwing the error that "It is not empty"目录为空但laravel没有擦除它,抛出“它不是空的”错误
【发布时间】:2018-03-27 14:17:13
【问题描述】:

我正在尝试删除许多在特定条件下已经为空的目录:

$noticias = Noticia::where('id_idioma', '2')->get();

    foreach($noticias as $noticia){

        $id = $noticia->id;
        $dirPath='images/noticias/'.$id.'/';
        rmdir($dirPath);

    }

这给了我错误: ErrorException: rmdir(images/noticias/10446/): 目录不为空 但是目录是空的,知道吗?我还尝试删除 $dirPath 中的最后一个“/”。

【问题讨论】:

  • 您可能有隐藏文件。 (即,以点开头的文件名。)
  • 不,没有隐藏文件。谢谢。
  • 您使用的是什么操作系统?
  • 我已经使用 MAMP Pro 在 Mac 上安装了本地服务器。

标签: php laravel directory rmdir


【解决方案1】:

我已经解决了使用File::deletedirectory($dirPath) 而不是rmdir($dirPath) 所以:

$noticias = Noticia::where('id_idioma', '2')->get();

foreach($noticias as $noticia){

    $id = $noticia->id;
    $dirPath='images/noticias/'.$id.'/';
    File::deletedirectory($dirPath);

}

别忘了加:use Illuminate\Support\Facades\File;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-08-20
    • 2014-03-12
    • 1970-01-01
    • 2010-12-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-04
    相关资源
    最近更新 更多