递归删除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");
我有以下代码应该 em>删除目录及其中的所有内容。 p>
它似乎工作正常但由于某种原因,我在代码运行时在我的应用引擎日志中收到以下警告 strong>。 p>
有谁知道为什么会发生这种情况或者是否有更好的方法来避免这些错误? p>
PHP警告:云存储错误:未找到/ base 第223行上的/data/home/runtimes/php/sdk/google/appengine/ext/cloud_storage_streams/CloudStorageDirectoryClient.php p>
blockquote>
function deleteDir($ dirPath )
{
if 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”);
code> pre>
div>
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.
So you don't actually need the rmdir($dirPath);
statement (I suspect that's the one causing the warning).