문제

I have been using fog for a while and it works great. I recently encountered a problem where I am traversing through each file in a directory

d = S3.directories.get(“XXXXX”, prefix: “XX”)

d.files.each do |f|
puts f.key
end

In this case f.key gives me not just the filename but also the prefix, for example it gives: pathtofile/file1.txt. How do I only get file1

Thank you

도움이 되었습니까?

해결책

Since the keys look like filenames, you can use File.basename:

d.files.each do |f|
  puts File.basename(f.key)
end
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top