Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to know whether a FileUtils command was successful?

Tags:

ruby

I don't see any return value from FileUtils commands.

I'd like to do something like:

really=(gets.chomp=="y")
if really
  success = FileUtils.rm_rf "./PROJECT_#{@name}" #does not work
end
puts "./PROJECT_#{@name} deleted" if success

I read the documentation for FileUtils, and also read a "Getting executed command from ruby FileUtils", but I cannot figure how to use the answer.

like image 998
JCLL Avatar asked Jan 24 '13 14:01

JCLL


1 Answers

According to the documentation ( http://ruby-doc.org/stdlib-1.9.3/libdoc/fileutils/rdoc/FileUtils.html#method-c-rm_rf ) calls to #rm_rf will not echo anything relevant to the task they are taking. #rm_rf actually calls #rm_r with option :force => true. This options enables the method to ignore the StandardError Exception (which would then communicate you something about the operation or why it is not working). Now, back to why it is failing. As somebody already commented, try with the option :secure => true. More info about this here: http://ruby-doc.org/stdlib-1.9.3/libdoc/fileutils/rdoc/FileUtils.html#method-c-remove_entry_secure . This is probably a permission issue.

like image 70
ChuckE Avatar answered Oct 12 '22 00:10

ChuckE