# Creating a directory with File.makedirs

**URL:** <https://rubytalk.org/t/creating-a-directory-with-file-makedirs/41096>\
**Category:** ruby-talk\
**Created:** [2 October 2007 05:11 UTC](https://rubytalk.org/t/creating-a-directory-with-file-makedirs/41096 "2007-10-02T05:11:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Peter\_Marks](https://avatars.discourse-cdn.com/v4/letter/p/fbc32d/32.png) [@Peter\_Marks](https://rubytalk.org/u/Peter_Marks)\
**Post date:** [2 October 2007 05:11 UTC](https://rubytalk.org/t/creating-a-directory-with-file-makedirs/41096/1 "2007-10-02T05:11:56Z")

</div>

I am trying to create a directory in Rails with the following code:

File.makedirs '/folder/subfolder/'

However, I get the error "undefined method `makedirs' for File:Class".  
Has makedirs been deprecated to something else?

Thanks,

peter

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

---

<div class="post-metadata">

**Author:** ![Phil4](https://avatars.discourse-cdn.com/v4/letter/p/45deac/32.png) [@Phil4](https://rubytalk.org/u/Phil4)\
**Post date:** [2 October 2007 06:45 UTC](https://rubytalk.org/t/creating-a-directory-with-file-makedirs/41096/2 "2007-10-02T06:45:04Z")

</div>

Peter Marks schrieb:

> I am trying to create a directory in Rails with the following code:
> 
> File.makedirs '/folder/subfolder/'
> 
> However, I get the error "undefined method `makedirs' for File:Class".  
> Has makedirs been deprecated to something else?
> 
> Thanks,
> 
> peter

makedir is a method defined in ftools (see [http://www.ruby-doc.org/core/classes/File.html\](http://www.ruby-doc.org/core/classes/File.html%5C)). Therefore - add  
require 'ftools'  
if you want to use this method.

Or even better use the corresponding method being defined in "FileUtils" module.

BR Phil

---

<div class="post-metadata">

**Author:** ![Peter\_Marks](https://avatars.discourse-cdn.com/v4/letter/p/fbc32d/32.png) [@Peter\_Marks](https://rubytalk.org/u/Peter_Marks)\
**Post date:** [2 October 2007 06:51 UTC](https://rubytalk.org/t/creating-a-directory-with-file-makedirs/41096/3 "2007-10-02T06:51:08Z")

</div>

Phil Meier wrote:

> require 'ftools'

ah, of course. Thanks for helping a neub Phil 🙂

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![Eric\_Hodel1](https://avatars.discourse-cdn.com/v4/letter/e/a9adbd/32.png) [@Eric\_Hodel1](https://rubytalk.org/u/Eric_Hodel1)\
**Post date:** [2 October 2007 08:17 UTC](https://rubytalk.org/t/creating-a-directory-with-file-makedirs/41096/4 "2007-10-02T08:17:56Z")

</div>

> Phil Meier wrote:
> 
> > require 'ftools'
> 
> ah, of course. Thanks for helping a neub Phil 🙂

FileUtils is the preferred way now. ftools.rb says:

> # FileUtils contains all or nearly all the same functionality and more, and  
> # is a recommended option over ftools
> 
> # See the method descriptions below, and consider using FileUtils as it is  
> # more comprehensive.

FileUtils.mkdir\_p makes directories recursively.

> **···**
>
> On Oct 1, 2007, at 23:51 , Peter Marks wrote:
> 
> --  
> Poor workers blame their tools. Good workers build better tools. The  
> best workers get their tools to do the work for them. -- Syndicate Wars
