doulang1945 2016-02-26 15:36
浏览 56
已采纳

递归删除Google云端存储中的文件夹

I have the following code that should delete the directory and everything inside it.

It seems to work fine but for some reason I get the following warnings in my app engine logs when the code runs.

Does anyone know why this would happen or if there is a better way to avoid these errors?

PHP Warning: Cloud Storage Error: NOT FOUND in /base/data/home/runtimes/php/sdk/google/appengine/ext/cloud_storage_streams/CloudStorageDirectoryClient.php on line 223

function deleteDir($dirPath) 
{
    if (! is_dir($dirPath)) {
        die("not a directory");
    }
    if (substr($dirPath, strlen($dirPath) - 1, 1) != '/') {
        $dirPath .= '/';
    }
    $files = glob($dirPath . '*', GLOB_MARK);
    foreach ($files as $file) {
        if (is_dir($file)) {
            deleteDir($file);
        } else {
            unlink($file);
        }
    }
    rmdir($dirPath);
}

deleteDir("gs://folder/folder");
  • 写回答

1条回答 默认 最新

  • drxdai15012937753 2016-02-26 16:09
    关注

    GCS doesn't actually have (sub)directories, they're "faked" by extracting them from the path-like segments of filenames:

    gsutil provides the illusion of a hierarchical file tree atop the “flat” name space supported by the Google Cloud Storage service. To the service, the object gs://your-bucket/abc/def/ghi.txt is just an object that happens to have “/” characters in its name. There are no “abc” or “abc/def” directories; just a single object with the given name.

    enter image description here

    So you don't actually need the rmdir($dirPath); statement (I suspect that's the one causing the warning).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?