Tell me how I can delete the folder with the files through the Ruby code. (I use version 1.9.2)
I read that you need to use FileUtils but I do not know what it is, and "what does it eat with?".

A piece of code:

class FileUtils Dir.rmdir ("Movies") end 

The error that occurred:

Mistake

PS I am too lazy to rename files by numbering in order to first delete them and then delete the folder itself.

  • Please note that even extended support for Ruby 1.9.2 ended in July 2014. - D-side

1 answer 1

There is a wonderful module (not a class!) FileUtils right in the standard library , where there is a whole kilogram of frequently performed operations on the file system. And there is a rm_r method, which recursively (by rm_r over the contents of nested folders) deletes the specified folder / file:

 FileUtils.rm_r('Movies') 
  • Ruby 2.3 also has such a module with this method - ruby-doc.org/stdlib-2.3.0/libdoc/fileutils/rdoc/… - MAXOPKA
  • @MAXOPKA just from the author 1.9.2. The remark at the end of the answer does not refer to the answer itself, it is rather a note for the author. And since I said it, I will make it a comment ... - D-side