Method: QcloudCos::ConvenientApi#exists?

Defined in:
lib/qcloud_cos/convenient_api.rb

#exists?(path = '/', options = {}) ⇒ Boolean Also known as: exist?

判断文件或者文件夹是否存在

Parameters:

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

    指定文件路径

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

    额外参数

Options Hash (options):

  • :bucket (String) — default: config.bucket

    指定当前 bucket, 默认是配置里面的 bucket

Returns:

  • (Boolean)
[View source]

73
74
75
76
77
78
79
# File 'lib/qcloud_cos/convenient_api.rb', line 73

def exists?(path = '/', options = {})
  return true if path == '/' || path.to_s.empty?
  result = stat(path, options)
  result.key?('data') && result['data'].key?('name')
rescue
  false
end