I'm sending the file file.txt
from my Rails controller using send_file
, and then delete the folder containing it.
send_file("#{Rails.root}/public/folder/file.txt")
FileUtils.remove_dir "#{Rails.root}/public/folder", true
When I did this, file.txt
was sent and deleted. However, folder
was not deleted. But if I remove the send_file
line, then folder
will be deleted.
How do I make it delete folder
?
EDIT: Interestingly, I found that inside folder
there is a hidden file called .__afs2B0C
, probably preventing the deletion. I have no idea how this file is created! The file stays for only around 15 minutes before disappearing.
EDIT2: I've tried inspecting the content of the temp file with vi
, but it's unreadable gibberish. When I removed only the send_file
line, the folder was correctly deleted. When I removed only the FileUtils.remove_dir
line, the folder contains no temp file.