怎么办“s3cmd LS S3:// some_bucket /富/栏”等值的红宝石? [英] How to do the equivalent of 's3cmd ls s3://some_bucket/foo/bar' in Ruby?

查看:273
本文介绍了怎么办“s3cmd LS S3:// some_bucket /富/栏”等值的红宝石?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要如何做相当于's3cmd LS S3:// some_bucket /富/酒吧?在Ruby中

How do I do the equivalent of 's3cmd ls s3://some_bucket/foo/bar' in Ruby?

我发现亚马逊S3宝石的红宝石,也是正确的AWS S3库,但不知何故,这不是显而易见如何在S3'文件夹'如位置做一个简单的'ls'的命令一样。

I found the Amazon S3 gem for Ruby and also the Right AWS S3 library, but somehow it's not immediately obvious how to do a simple 'ls' like command on an S3 'folder' like location.

推荐答案

该负责人Ruby的AWS SDK现在支持这一点:的 http://docs.aws.amazon.com/AWSRubySDK/latest/AWS/S3/Tree.html

The official Ruby AWS SDK now supports this: http://docs.aws.amazon.com/AWSRubySDK/latest/AWS/S3/Tree.html

您还可以添加以下的简便方法:

You can also add the following convenience method:

class AWS::S3::Bucket
  def ls(path)
    as_tree(:prefix => path).children.select(&:branch?).map(&:prefix)
  end
end

然后,使用这样的:

Then use it like this:

mybucket.ls 'foo/bar' # => ["/foo/bar/dir1/", "/foo/bar/dir2/"]

这篇关于怎么办“s3cmd LS S3:// some_bucket /富/栏”等值的红宝石?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆