# Creating a directory with File.makedirs

**URL:** <https://www.ruby-forum.com/t/creating-a-directory-with-file-makedirs/116084>\
**Category:** Ruby\
**Created:** [October 2, 2007, 7:11am UTC](https://www.ruby-forum.com/t/creating-a-directory-with-file-makedirs/116084 "2007-10-02T07:11:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dracos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ea666f/32.png) [@dracos](https://www.ruby-forum.com/u/dracos)\
**Post date:** [October 2, 2007, 7:11am UTC](https://www.ruby-forum.com/t/creating-a-directory-with-file-makedirs/116084/1 "2007-10-02T07:11:55Z")

</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

---

<div class="post-metadata">

**Author:** ![dracos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ea666f/32.png) [@dracos](https://www.ruby-forum.com/u/dracos)\
**Post date:** [October 2, 2007, 8:46am UTC](https://www.ruby-forum.com/t/creating-a-directory-with-file-makedirs/116084/2 "2007-10-02T08:46:35Z")

</div>

Peter M. 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  
[class File - RDoc Documentation](http://www.ruby-doc.org/core/classes/File.html)). 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:** ![dracos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ea666f/32.png) [@dracos](https://www.ruby-forum.com/u/dracos)\
**Post date:** [October 2, 2007, 8:51am UTC](https://www.ruby-forum.com/t/creating-a-directory-with-file-makedirs/116084/3 "2007-10-02T08:51:05Z")

</div>

Phil M. wrote:

> require ‘ftools’

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

---

<div class="post-metadata">

**Author:** ![dracos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ea666f/32.png) [@dracos](https://www.ruby-forum.com/u/dracos)\
**Post date:** [October 2, 2007, 10:18am UTC](https://www.ruby-forum.com/t/creating-a-directory-with-file-makedirs/116084/4 "2007-10-02T10:18:29Z")

</div>

On Oct 1, 2007, at 23:51 , Peter M. wrote:

> Phil M. 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.
