Method: COS::Bucket#list

Defined in:
lib/cos/bucket.rb

#list(path = '', options = {}) ⇒ Enumerator<Object> Also known as: ls

列出目录

Examples:

all = bucket.list
all.each do |o|
  if o.is_a?(COS::COSFile)
    puts "File: #{o.name} #{o.format_size}"
  else
    puts "Dir: #{o.name} #{o.created_at}"
  end
end

Parameters:

  • path (String) (defaults to: '')

    目录路径, 如: ‘/’, ‘path1’, ‘path1/path2’, sdk会补齐末尾的 ‘/’

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :prefix (String)

    搜索前缀如果填写prefix, 则列出含此前缀的所有文件及目录

  • :num (Integer)

    每页拉取的数量, 默认20条

  • :pattern (Symbol)

    获取方式:dir_only 只获取目录, :file_only 只获取文件, 默认为 :both 全部获取

  • :order (Symbol)

    排序方式 :asc 正序, :desc 倒序 默认为 :asc

Returns:

  • (Enumerator<Object>)

    迭代器, 其中Object可能是COS::COSFile或COS::COSDir

Raises:



168
169
170
# File 'lib/cos/bucket.rb', line 168

def list(path = '', options = {})
  Resource.new(self, path, options).to_enum
end