我有一个GCS存储桶包含路径中的一些文件
GS://main-bucket/sub-directory-bucket/object1.gz
我想以编程方式检查子目录存储桶是否包含一个特定文件。我想用gsutil来做这件事。
怎么可以这样做?
您可以使用gsutil stat命令。
使用gsutil stat命令。要访问具有更多文件数的子目录,请使用通配符(*)。
例如:
gsutil -q stat gs://some-bucket/some-subdir/*; echo $?
在你的情况下:
gsutil -q stat gs://main-bucket/sub-directory-bucket/*; echo $?
结果0表示存在; 1表示不存在
还有gsutil ls
(https://cloud.google.com/storage/docs/gsutil/commands/ls)
EG
gsutil ls gs://my-bucket/foo.txt
输出是相同的文件路径或“CommandException: One or more URLs matched no objects.
”