【发布时间】:2026-02-11 12:50:01
【问题描述】:
使用 Google Drive API v3 时,是否可以使用通配符或正则表达式按文件名搜索文件? The docs什么都别提。
我正在尝试匹配一组名称具有以下格式的文件
backup_YYYY-MM-DD-XXXX_NameOfWebsite_xxxxxxxxxx.zip
我想知道构建可能匹配它的模式的最佳方法是什么。当然,我可以按照文档进行操作,然后执行以下操作:
q="name contains 'backup' and name contains 'NameOfWebsite'"
但如果我需要匹配不同的模式,或者文件名中有超过 2 个不同字符串的东西("backup_" 和 "NameOfWebsite"),您可以快速了解以这种方式构造查询是多么痛苦:
q="name contains 'string1' and name contains 'string2' and name contains...
【问题讨论】:
-
你不能把你的字符串变量传入你的查询字符串吗?如果
*是通配符,则执行q="name contains 'backup' and name contains 'NameOfWebsite'"与执行q="name = '*backup*NameOfWebsite*'"相同。 -
您不能在
q搜索词中使用通配符。您必须对name contains查询进行字符串处理。 -
也来自文档:
The contains operator only performs prefix matching for a name. For example, the name "HelloWorld" would match for name contains 'Hello' but not name contains 'World'.因此,如果前面没有空格,则不能在文件名中间使用name contains 'NameOfWebsite'。阅读更多关于包含here
标签: google-drive-api