# Trouble with FileUtils.rm\_rf / .rmdir

**URL:** <https://www.ruby-forum.com/t/trouble-with-fileutils-rm-rf-rmdir/71483>\
**Category:** Ruby\
**Created:** [February 21, 2006, 7:10pm UTC](https://www.ruby-forum.com/t/trouble-with-fileutils-rm-rf-rmdir/71483 "2006-02-21T19:10:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![James\_BSByrne](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/838e76/32.png) [@James\_BSByrne](https://www.ruby-forum.com/u/James_BSByrne)\
**Post date:** [February 21, 2006, 7:10pm UTC](https://www.ruby-forum.com/t/trouble-with-fileutils-rm-rf-rmdir/71483/1 "2006-02-21T19:10:55Z")

</div>

I am trying to dynamically setup and teardown a directory structure for  
testing. The code that I am using employs .rm\_rf but I get the same  
results if I use  
.rmdir instead.

#-------------------------------------------------------------------------  
$:.unshift File.join(File.dirname( **FILE** ), “…”, “lib”)

require ‘test/unit’  
require ‘fileutils’  
require ‘mv2dir’

class Test\_Mv2Dir \< Test::Unit::TestCase

# What are we going to test for?

#1. Test that instances test for valid directories and return

# TRUE or FALSE as expected.

def test\_dir  
#-- a. define test directories  
dir\_test =  
["~/tmp/mv2dir/test/source/","~/tmp/mv2dir/test/target/"]  
#-- b. clear them out:  
dir\_test.each do |dt|  
puts dt  
FileUtils.rm\_rf(dt, :verbose =\> TRUE, :secure =\> TRUE)

# FileUtils.rmdir(dt, :verbose =\> TRUE) rescue Errno::ENOENT

```
end

```

…  
#---------------------------------------------------------------------------

These are the results. ~/tmp/mv2dir/test/target exists before the run.  
It is my intention that it be gone at the end of the run. It is not.  
Can  
anyone point out to me what I am doing wrong?

ll ~/tmp/mv2dir/test/  
total 8  
drwxrwxr-x 2 byrnejb byrnejb 4096 Feb 21 12:11 target  
[byrnejb@inet05 test]$ ruby mv2dir\_tc.rb  
Loaded suite mv2dir\_tc  
Started  
~/tmp/mv2dir/test/source/  
rm -rf ~/tmp/mv2dir/test/source/  
~/tmp/mv2dir/test/target/  
rm -rf ~/tmp/mv2dir/test/target/  
…  
Finished in 0.002761 seconds.

3 tests, 0 assertions, 0 failures, 0 errors  
[byrnejb@inet05 test]$ ll ~/tmp/mv2dir/test/  
total 8  
drwxrwxr-x 2 byrnejb byrnejb 4096 Feb 21 12:11 target

---

<div class="post-metadata">

**Author:** ![James\_BSByrne](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/838e76/32.png) [@James\_BSByrne](https://www.ruby-forum.com/u/James_BSByrne)\
**Post date:** [February 21, 2006, 7:54pm UTC](https://www.ruby-forum.com/t/trouble-with-fileutils-rm-rf-rmdir/71483/2 "2006-02-21T19:54:27Z")

</div>

I can get this to work if I force :secure =\> FALSE but I do not see why  
that should be necessary. None of the directories in the path  
/home/byrnejb/tmp/mv2dir/test/target are world writeable. However,  
unless I call FileUtils.rm\_r(dt,:secure =\> FALSE) the directory is not  
removed. Can someone explain to me what I am misunderstanding with  
respect to the documentation?
