在python中使用Gcs匹配glob参数来获取子目录下的特定文件

问题描述 投票:0回答:1

我正在尝试从给定存储桶中获取特定文件:

my_bucket
  dirA
    dirX
      file1.json
      file2.json
      file1.csv

    dirY
      file2.csv

  dirZ
    dirX
      file3.json
      file3.csv

使用python的sdk“match_glob”参数,我想仅获取符合

**/dirX/**.json
模式的文件。

即:我想得到

dirA/dirX/file1.json
dirA/dirX/file2.json
dirZ/dirX/file3.json
文件。

尝试

**/dirX/**.json
模式产生空结果。

这个模式有什么问题吗?

提前致谢!

python google-cloud-storage glob
1个回答
0
投票

您可以尝试使用此模式

**/*.json
而不是
 **/dirX/**.json
,因为它会返回空结果,因为dirX不是存储桶根目录上的目录,而是dirA和dirZ的子目录。

您可以像

**/*.json
一样使用match_glob参数,此模式将获取存储桶中任何目录的dirX子目录中的所有.json文件。

当 matchGlob 查询参数设置为 glob 模式时,对象列表操作仅返回与 items[] 中的 glob 模式匹配的对象。您可以检查此使用 glob 列出对象和前缀

© www.soinside.com 2019 - 2024. All rights reserved.