Pergunta

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

Foi útil?

Solução

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

d.files.each do |f|
  puts File.basename(f.key)
end
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top