Delete a folder containing a file

I want to send file.txt from my Rails controller using send_file and then delete the folder containing it.

 send_file("#{Rails.root}/public/folder/file.txt") system("rm -rf #{Rails.root}/public/folder") 

When I tried this, file.txt was sent correctly, file.txt was deleted correctly, but somehow the folder not deleted.

How can I delete its folder ?

+3
source share
1 answer

Try to delete the folder directly using your own ruby ​​method instead of the system command:

 require 'fileutils' FileUtils.remove_dir "#{Rails.root}/public/folder", true 

http://www.ruby-doc.org/stdlib-1.9.3/libdoc/fileutils/rdoc/FileUtils.html#method-c-remove_dir

+3
source

Source: https://habr.com/ru/post/1445639/


All Articles