1

i am creating temp zip file in rails tmp directory as follows:-

zipfile_name = Rails.root.join("tmp/abc.zip")
Zip::File.open(zipfile_name, Zip::File::CREATE) do |zipfile|
  Dir[File.join(data, '**',)].each do |file|
    zipfile.add(file.sub(dir+"/", ''), file)
  end
end
zip_data = File.read(zipfile_name) # sending zip file.
zipfile_name.try(:unlink)`         # try to remove or unlink the zip but not working. 

temp zipfile_name was abc.zip20140816-8931-1yl3g60 and i want to delete it after sending but it's not found.

Harish Shetty
  • 64,083
  • 21
  • 152
  • 198
Gaurav Sharma
  • 477
  • 9
  • 24
  • Try `Zip::File.open(zipfile_name.to_s, Zip::File::CREATE)`.. If it works, let me know..I will explain why.. – Arup Rakshit Aug 16 '14 at 18:25
  • zipfile_name.to_s is working as same but i am using this block in Dir.mktmpdir so everytime .zip file also have tmp name that i explained above abc.zip20140816-8931-1yl3g60 – Gaurav Sharma Aug 16 '14 at 18:48

1 Answers1

0
File.delete(zipfile_name)

Try file delete command it should work out.

coderhs
  • 4,357
  • 1
  • 16
  • 25