سؤال

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