在Google云端存储上批量重命名对象 [英] Mass rename objects on Google Cloud Storage
问题描述
是否可以使用gsutil(或其他工具)在Google云端存储上批量重命名对象?我试图找出一种方法来将一堆图像从* .JPG重命名为* .jpg。
>
https://cloud.google.com/storage/docs/ gsutil / addlhelp / WildcardNames
gsutil支持URI通配符
编辑
gsutil 3.0 release note 我们改变了*通配符以仅匹配目录边界,并引入了新的通配符...
<你有没有目录下的桶?如果是这样,也许你需要去每个目录或使用**。
gsutil -m mv gs:// my_bucket /**.JPG gs://my_bucket/**.jpg
或
gsutil -m mv gs://my_bucket/mydir/*.JPG gs://my_bucket/mydir/*.jpg
编辑
gsutil doesn' t到目前为止支持目的地通配符(截至2014年4月12日)
nether API 。
所以现在您需要检索所有JPG文件列表,
并重命名每个文件。 / b>
python示例:
导入子流程
pre>
文件=子流程.check_output(gsutil ls gs://my_bucket/*.JPG,shell = True)
files = files.split(\\\
)[: - 1]
for f in files :
subprocess.call(gsutil mv%s%s%(f,f [: - 3] +jpg),shell = True)
请注意这样做需要数小时。
Is it possible to mass rename objects on Google Cloud Storage using gsutil (or some other tool)? I am trying to figure out a way to rename a bunch of images from *.JPG to *.jpg.
解决方案
https://cloud.google.com/storage/docs/gsutil/addlhelp/WildcardNamesgsutil supports URI wildcards
EDIT
As part of the bucket sub-directory support we changed the * wildcard to match only up to directory boundaries, and introduced the new ** wildcard...
Do you have directories under bucket? if so, maybe you need to go down to each directories or use **.
gsutil -m mv gs://my_bucket/**.JPG gs://my_bucket/**.jpg
or
gsutil -m mv gs://my_bucket/mydir/*.JPG gs://my_bucket/mydir/*.jpg
EDIT
gsutil doesn't support wildcard for destination so far (as of 4/12/'14)
nether API.so at this moment you need to retrieve list of all JPG files, and rename each files.
python example:
import subprocess files = subprocess.check_output("gsutil ls gs://my_bucket/*.JPG",shell=True) files = files.split("\n")[:-1] for f in files: subprocess.call("gsutil mv %s %s"%(f,f[:-3]+"jpg"),shell=True)
please note that this would take hours.
这篇关于在Google云端存储上批量重命名对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!