# Problems with FileUtils in Rake

**URL:** <https://rubytalk.org/t/problems-with-fileutils-in-rake/12204>\
**Category:** ruby-talk\
**Created:** [19 June 2004 08:38 UTC](https://rubytalk.org/t/problems-with-fileutils-in-rake/12204 "2004-06-19T08:38:20Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Charles\_Comstock](https://avatars.discourse-cdn.com/v4/letter/c/91b2a8/32.png) [@Charles\_Comstock](https://rubytalk.org/u/Charles_Comstock)\
**Post date:** [19 June 2004 08:38 UTC](https://rubytalk.org/t/problems-with-fileutils-in-rake/12204/1 "2004-06-19T08:38:20Z")

</div>

Why is it that the following rakefile code works:

task :examples do  
&nbsp;&nbsp;&nbsp;sh %{rm -rf ~/.ruby\_inline}  
&nbsp;&nbsp;&nbsp;ruby %{-Ilib/inline.rb -w bench/example.rb}  
&nbsp;&nbsp;&nbsp;sh %{rm -rf ~/.ruby\_inline}  
&nbsp;&nbsp;&nbsp;ruby %{-Ilib/inline.rb -w bench/example2.rb}  
&nbsp;&nbsp;&nbsp;sh %{rm -rf ~/.ruby\_inline}  
&nbsp;&nbsp;&nbsp;ruby %{-Ilib/inline.rb -w tutorial/example1.rb}  
&nbsp;&nbsp;&nbsp;sh %{rm -rf ~/.ruby\_inline}  
&nbsp;&nbsp;&nbsp;ruby %{-Ilib/inline.rb -w tutorial/example2.rb}  
end

produces valid output of:

[761 cc1@earwig ~/install/RubyInline-3.0.1]$ rake examples  
(in /.autofs/home/s/c/cc1/install/RubyInline-3.0.1)  
rm -rf ~/.ruby\_inline  
ruby -Ilib/inline.rb -w bench/example.rb  
Type = Inline C , Iter = 1000000, T = 1.59424400 sec, 0.00000159 sec / iter  
rm -rf ~/.ruby\_inline  
ruby -Ilib/inline.rb -w bench/example2.rb  
hello  
rm -rf ~/.ruby\_inline  
ruby -Ilib/inline.rb -w tutorial/example1.rb  
......  
rm -rf ~/.ruby\_inline  
ruby -Ilib/inline.rb -w tutorial/example2.rb  
......

but

task :examples do  
&nbsp;&nbsp;&nbsp;rm\_rf %{~/.ruby\_inline}  
&nbsp;&nbsp;&nbsp;ruby %{-Ilib/inline.rb -w bench/example.rb}  
&nbsp;&nbsp;&nbsp;rm\_rf %{~/.ruby\_inline}  
&nbsp;&nbsp;&nbsp;ruby %{-Ilib/inline.rb -w bench/example2.rb}  
&nbsp;&nbsp;&nbsp;rm\_rf %{~/.ruby\_inline}  
&nbsp;&nbsp;&nbsp;ruby %{-Ilib/inline.rb -w tutorial/example1.rb}  
&nbsp;&nbsp;&nbsp;rm\_rf %{~/.ruby\_inline}  
&nbsp;&nbsp;&nbsp;ruby %{-Ilib/inline.rb -w tutorial/example2.rb}  
end

produces:

[762 cc1@earwig ~/install/RubyInline-3.0.1]$ rake examples  
(in /.autofs/home/s/c/cc1/install/RubyInline-3.0.1)  
rm -rf ~/.ruby\_inline  
ruby -Ilib/inline.rb -w bench/example.rb  
Type = Inline C , Iter = 1000000, T = 1.83316400 sec, 0.00000183 sec / iter  
rm -rf ~/.ruby\_inline  
ruby -Ilib/inline.rb -w bench/example2.rb  
bench/example2.rb:29: undefined method `hello' for #\<MyTest:0x4007fa00\> (NoMethodError)  
rake aborted!  
Command Failed: [ruby -Ilib/inline.rb -w bench/example2.rb]  
../Rakefile:61

both of these tests are using:

ruby 1.8.2 (2004-06-04) [i686-linux]

My assumption is that FileUtils.rm\_rf is not actually doing it's job. This is validated by the fact that ~/.ruby\_inline does not appear to be correctly deleted in the second example.

So why is it FileUtils.rm\_rf is not doing it's job when it should just call through to rm -rf?

Charles Comstock

---

<div class="post-metadata">

**Author:** ![Nobuyoshi\_Nakada](https://avatars.discourse-cdn.com/v4/letter/n/edb3f5/32.png) [@Nobuyoshi\_Nakada](https://rubytalk.org/u/Nobuyoshi_Nakada)\
**Post date:** [19 June 2004 09:02 UTC](https://rubytalk.org/t/problems-with-fileutils-in-rake/12204/2 "2004-06-19T09:02:40Z")

</div>

Hi,

At Sat, 19 Jun 2004 17:38:20 +0900,  
Charles Comstock wrote in [ruby-talk:104116]:

> task :examples do  
> &nbsp;&nbsp;&nbsp;rm\_rf %{~/.ruby\_inline}

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rm\_rf File.expand\_path(%{~/.ruby\_inline})

FileUtils itself doesn't do tilde-expansion.

> **···**
>
> --  
> Nobu Nakada

---

<div class="post-metadata">

**Author:** ![Charles\_Comstock](https://avatars.discourse-cdn.com/v4/letter/c/91b2a8/32.png) [@Charles\_Comstock](https://rubytalk.org/u/Charles_Comstock)\
**Post date:** [19 June 2004 10:03 UTC](https://rubytalk.org/t/problems-with-fileutils-in-rake/12204/3 "2004-06-19T10:03:20Z")

</div>

Ah. Hmm. Is there a way to force it to do tilde expansion if the functionality is available? The application won't work without posix support anyway, so isn't this something we could assume? Or is that an unfair assumption? What is the preferred way to deal with this?

Charles Comstock

> **···**
>
> nobu.nokada@softhome.net wrote:
> 
> > Hi,
> > 
> > At Sat, 19 Jun 2004 17:38:20 +0900,  
> > Charles Comstock wrote in [ruby-talk:104116]:
> > 
> > > task :examples do  
> > > &nbsp;&nbsp;rm\_rf %{~/.ruby\_inline}
> > 
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rm\_rf File.expand\_path(%{~/.ruby\_inline})
> > 
> > FileUtils itself doesn't do tilde-expansion.

---

<div class="post-metadata">

**Author:** ![Nobuyoshi\_Nakada](https://avatars.discourse-cdn.com/v4/letter/n/edb3f5/32.png) [@Nobuyoshi\_Nakada](https://rubytalk.org/u/Nobuyoshi_Nakada)\
**Post date:** [19 June 2004 11:09 UTC](https://rubytalk.org/t/problems-with-fileutils-in-rake/12204/4 "2004-06-19T11:09:59Z")

</div>

Hi,

At Sat, 19 Jun 2004 19:03:20 +0900,  
Charles Comstock wrote in [ruby-talk:104118]:

> \>\>task :examples do  
> \>\> rm\_rf %{~/.ruby\_inline}  
> \>  
> \>  
> \> rm\_rf File.expand\_path(%{~/.ruby\_inline})  
> \>  
> \> FileUtils itself doesn't do tilde-expansion.  
> \>
> 
> Ah. Hmm. Is there a way to force it to do tilde expansion if the  
> functionality is available? The application won't work without posix  
> support anyway, so isn't this something we could assume? Or is that an  
> unfair assumption? What is the preferred way to deal with this?

Which application do you mention about, Rake?

Including this module may work, instead of FileUtils:

&nbsp;&nbsp;module Tilde  
&nbsp;&nbsp;&nbsp;&nbsp;module\_function  
&nbsp;&nbsp;&nbsp;&nbsp;def rm\_rf(\*args)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;args.collect!{|n|File.expand\_path(n) rescue break}  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FileUtils.rm\_rf(\*args)  
&nbsp;&nbsp;&nbsp;&nbsp;end  
&nbsp;&nbsp;end

> **···**
>
> --  
> Nobu Nakada
