Forum: Ruby mkdirs function?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
uval (Guest)
on 2005-11-21 23:55
(Received via mailing list)
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
pertl (Guest)
on 2005-11-21 23:59
(Received via mailing list)
piece of cake :-)

   def mkdirs(*dirs)
    dirs.each do |dir| Dir.mkdir(dir) end
   end

   mkdirs "dir1", "dir2" , "dir3"
rascal1182 (Guest)
on 2005-11-22 00:03
(Received via mailing list)
On 11/21/05, Daniel Schüle <removed_email_address@domain.invalid> 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.
damphyr (Guest)
on 2005-11-22 00:11
(Received via mailing list)
Rob R. wrote:
> ---
>
> File.makepath is also a sysnonym.
>
and mkdir_p :)
V.-

--
http://www.braveworld.net/riva
uval (Guest)
on 2005-11-22 00:15
(Received via mailing list)
Rob R. wrote:
> On 11/21/05, Daniel Schüle <removed_email_address@domain.invalid> 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
damphyr (Guest)
on 2005-11-22 00:19
(Received via mailing list)
Daniel Schüle wrote:
>> 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.-

--
http://www.braveworld.net/riva
uval (Guest)
on 2005-11-22 00:23
(Received via mailing list)
Hi

Damphyr wrote:
>> 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
         from (irb):71
         from :0
irb(main):072:0> File.mkdir_p
NoMethodError: undefined method `mkdir_p' for File:Class
         from (irb):72
         from :0
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
rascal1182 (Guest)
on 2005-11-22 00:31
(Received via mailing list)
On 11/21/05, Damphyr <removed_email_address@domain.invalid> wrote:
> Rob R. wrote:
> > ---
> > require 'ftools'
> >
> > File.makedirs ("/path/that/does/not/exist")
> > ---
> >
> > File.makepath is also a sysnonym.
> >
> and mkdir_p :)

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.

---
require 'fileutils'

FileUtils::mkdir_p("/path/that/does/not/exist")
---

...
rascal1182 (Guest)
on 2005-11-22 00:39
(Received via mailing list)
On 11/21/05, Daniel Schüle <removed_email_address@domain.invalid> wrote:
> irb(main):070:0> File.makedirs
> => []
> irb(main):071:0> File.makepath
> NoMethodError: undefined method `makepath' for File:Class
>          from (irb):71
>          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.
This topic is locked and can not be replied to.