# Mkdirs function?

**URL:** <https://rubytalk.org/t/mkdirs-function/22663>\
**Category:** ruby-talk\
**Created:** [21 November 2005 21:52 UTC](https://rubytalk.org/t/mkdirs-function/22663 "2005-11-21T21:52:24Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Daniel\_Schule](https://avatars.discourse-cdn.com/v4/letter/d/958977/32.png) [@Daniel\_Schule](https://rubytalk.org/u/Daniel_Schule)\
**Post date:** [21 November 2005 21:52 UTC](https://rubytalk.org/t/mkdirs-function/22663/1 "2005-11-21T21:52:24Z")

</div>

Hello all,

is there a function to make multiple directories  
like os.makedirs in Python?

I tried Dir.singleton\_methods but nothing that  
would fit.  
if not can it be added to Ruby?

Regards, Daniel

---

<div class="post-metadata">

**Author:** ![Pete1](https://avatars.discourse-cdn.com/v4/letter/p/67e7ee/32.png) [@Pete1](https://rubytalk.org/u/Pete1)\
**Post date:** [21 November 2005 21:56 UTC](https://rubytalk.org/t/mkdirs-function/22663/2 "2005-11-21T21:56:45Z")

</div>

piece of cake 🙂

&nbsp;&nbsp;&nbsp;def mkdirs(\*dirs)  
&nbsp;&nbsp;&nbsp;&nbsp;dirs.each do |dir| Dir.mkdir(dir) end  
&nbsp;&nbsp;&nbsp;end

&nbsp;&nbsp;&nbsp;mkdirs "dir1", "dir2" , "dir3"

> **···**
>
> On Mon, 21 Nov 2005 22:52:24 +0100, Daniel Schüle \<uval@rz.uni-karlsruhe.de\> wrote:
> 
> > Hello all,
> > 
> > is there a function to make multiple directories  
> > like os.makedirs in Python?
> > 
> > I tried Dir.singleton\_methods but nothing that  
> > would fit.  
> > if not can it be added to Ruby?
> > 
> > Regards, Daniel

---

<div class="post-metadata">

**Author:** ![Rob\_Rypka](https://avatars.discourse-cdn.com/v4/letter/r/e47c2d/32.png) [@Rob\_Rypka](https://rubytalk.org/u/Rob_Rypka)\
**Post date:** [21 November 2005 21:59 UTC](https://rubytalk.org/t/mkdirs-function/22663/3 "2005-11-21T21:59:25Z")

</div>

> is there a function to make multiple directories  
> like os.makedirs in Python?

> **···**
>
> On 11/21/05, Daniel Schüle \<uval@rz.uni-karlsruhe.de\> wrote:  
> ---  
> require 'ftools'
> 
> File.makedirs ("/path/that/does/not/exist")  
> ---
> 
> File.makepath is also a sysnonym.
> 
> --  
> Rob

---

<div class="post-metadata">

**Author:** ![Damphyr](https://avatars.discourse-cdn.com/v4/letter/d/7993a0/32.png) [@Damphyr](https://rubytalk.org/u/Damphyr)\
**Post date:** [21 November 2005 22:09 UTC](https://rubytalk.org/t/mkdirs-function/22663/4 "2005-11-21T22:09:12Z")

</div>

Rob Rypka wrote:

> **···**
>
> > On 11/21/05, Daniel Schüle \<uval@rz.uni-karlsruhe.de\> wrote:
> > 
> > > is there a function to make multiple directories  
> > > like os.makedirs in Python?
> > 
> > ---  
> > require 'ftools'
> > 
> > File.makedirs ("/path/that/does/not/exist")  
> > ---
> > 
> > File.makepath is also a sysnonym.
> 
> and mkdir\_p 🙂  
> V.-
> 
> --  
> [http://www.braveworld.net/riva](http://www.braveworld.net/riva)
> 
> \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> [http://www.freemail.gr](http://www.freemail.gr) - äùñåÜí õðçñåóßá çëåêôñïíéêïý ôá÷õäñïìåßïõ.  
> [http://www.freemail.gr](http://www.freemail.gr) - free email service for the Greek-speaking.

---

<div class="post-metadata">

**Author:** ![Daniel\_Schule](https://avatars.discourse-cdn.com/v4/letter/d/958977/32.png) [@Daniel\_Schule](https://rubytalk.org/u/Daniel_Schule)\
**Post date:** [21 November 2005 22:12 UTC](https://rubytalk.org/t/mkdirs-function/22663/5 "2005-11-21T22:12:29Z")

</div>

Rob Rypka wrote:

> > is there a function to make multiple directories  
> > like os.makedirs in Python?
> 
> ---  
> require 'ftools'
> 
> File.makedirs ("/path/that/does/not/exist")

thx, that's what I looked for  
I expected it to be a method of Dir

> File.makepath is also a sysnonym.

Regards, Daniel

> **···**
>
> > On 11/21/05, Daniel Schüle \<uval@rz.uni-karlsruhe.de\> wrote:

---

<div class="post-metadata">

**Author:** ![Damphyr](https://avatars.discourse-cdn.com/v4/letter/d/7993a0/32.png) [@Damphyr](https://rubytalk.org/u/Damphyr)\
**Post date:** [21 November 2005 22:16 UTC](https://rubytalk.org/t/mkdirs-function/22663/6 "2005-11-21T22:16:23Z")

</div>

Daniel Schüle wrote:

> Rob Rypka wrote:
> 
> > > is there a function to make multiple directories  
> > > like os.makedirs in Python?
> > 
> > ---  
> > require 'ftools'
> > 
> > File.makedirs ("/path/that/does/not/exist")
> 
> thx, that's what I looked for  
> I expected it to be a method of Dir

They're actually definedd in module FileUtils.  
V.-

> **···**
>
> > > On 11/21/05, Daniel Schüle \<uval@rz.uni-karlsruhe.de\> wrote:
> 
> --  
> [http://www.braveworld.net/riva](http://www.braveworld.net/riva)
> 
> \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> [http://www.freemail.gr](http://www.freemail.gr) - äùñåÜí õðçñåóßá çëåêôñïíéêïý ôá÷õäñïìåßïõ.  
> [http://www.freemail.gr](http://www.freemail.gr) - free email service for the Greek-speaking.

---

<div class="post-metadata">

**Author:** ![Daniel\_Schule](https://avatars.discourse-cdn.com/v4/letter/d/958977/32.png) [@Daniel\_Schule](https://rubytalk.org/u/Daniel_Schule)\
**Post date:** [21 November 2005 22:22 UTC](https://rubytalk.org/t/mkdirs-function/22663/7 "2005-11-21T22:22:24Z")

</div>

Hi

Damphyr wrote:

> Rob Rypka wrote:
> 
> > > is there a function to make multiple directories  
> > > like os.makedirs in Python?
> > 
> > ---  
> > require 'ftools'
> > 
> > File.makedirs ("/path/that/does/not/exist")  
> > ---
> > 
> > File.makepath is also a sysnonym.
> 
> and mkdir\_p 🙂

irb(main):070:0\> File.makedirs  
=\>   
irb(main):071:0\> File.makepath  
NoMethodError: undefined method `makepath' for File:Class  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from (irb):71  
irb(main):072:0\> File.mkdir\_p  
NoMethodError: undefined method `mkdir\_p' for File:Class  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from (irb):72  
irb(main):073:0\>

File.makepath and File.mkdir\_p seem to be undefined  
as for the names I think makepath is a pretty fitting name  
but I dont like abbrevations like mkdir\_p  
I always start guessing what may p stand for  
File.makedirs is also very suitable name 🙂

Regards, Daniel

> **···**
>
> > > On 11/21/05, Daniel Schüle \<uval@rz.uni-karlsruhe.de\> wrote:
> 
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from :0

---

<div class="post-metadata">

**Author:** ![Rob\_Rypka](https://avatars.discourse-cdn.com/v4/letter/r/e47c2d/32.png) [@Rob\_Rypka](https://rubytalk.org/u/Rob_Rypka)\
**Post date:** [21 November 2005 22:30 UTC](https://rubytalk.org/t/mkdirs-function/22663/8 "2005-11-21T22:30:39Z")

</div>

mkdir\_p is not in ftools. It \*is\* in FileUtils. It is  
Recommended(tm) that you use FileUtils instead of ftools, but I'm  
lazy, and didn't look it up.

> **···**
>
> On 11/21/05, Damphyr \<damphyr@freemail.gr\> wrote:
> 
> > Rob Rypka wrote:  
> > \> ---  
> > \> require 'ftools'  
> > \>  
> > \> File.makedirs ("/path/that/does/not/exist")  
> > \> ---  
> > \>  
> > \> File.makepath is also a sysnonym.  
> > \>  
> > and mkdir\_p 🙂
> 
> ---  
> require 'fileutils'
> 
> FileUtils::mkdir\_p("/path/that/does/not/exist")  
> ---
> 
> ...
> 
> --  
> Rob

---

<div class="post-metadata">

**Author:** ![Rob\_Rypka](https://avatars.discourse-cdn.com/v4/letter/r/e47c2d/32.png) [@Rob\_Rypka](https://rubytalk.org/u/Rob_Rypka)\
**Post date:** [21 November 2005 22:35 UTC](https://rubytalk.org/t/mkdirs-function/22663/9 "2005-11-21T22:35:33Z")

</div>

> irb(main):070:0\> File.makedirs  
> =\>   
> irb(main):071:0\> File.makepath  
> NoMethodError: undefined method `makepath' for File:Class  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from (irb):71  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from :0

Sorry, that should be File.mkpath.

> File.makepath and File.mkdir\_p seem to be undefined  
> as for the names I think makepath is a pretty fitting name  
> but I dont like abbrevations like mkdir\_p

mkdir\_p is named as such because UNIX users get the same functionality  
from 'mkdir -p' at the command line.

p stands for parents, as the parent directories are also created if necessary.

> **···**
>
> On 11/21/05, Daniel Schüle \<uval@rz.uni-karlsruhe.de\> wrote:
> 
> --  
> Rob
