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.
8d6f5daee16e380ce0ac00395b417fb6?d=identicon&s=25 uval (Guest)
on 2005-11-21 22: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
36958dd94ca666a38483df282a5214d5?d=identicon&s=25 pertl (Guest)
on 2005-11-21 22:59
(Received via mailing list)
piece of cake :-)

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

   mkdirs "dir1", "dir2" , "dir3"
Eba32a4bc6f1a4f60b434b7cae0715de?d=identicon&s=25 rascal1182 (Guest)
on 2005-11-21 23:03
(Received via mailing list)
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.
Cfdeff3ac35010e4de8f85d954f24f4a?d=identicon&s=25 damphyr (Guest)
on 2005-11-21 23:11
(Received via mailing list)
Rob Rypka wrote:
> ---
>
> File.makepath is also a sysnonym.
>
and mkdir_p :)
V.-

--
http://www.braveworld.net/riva
8d6f5daee16e380ce0ac00395b417fb6?d=identicon&s=25 uval (Guest)
on 2005-11-21 23:15
(Received via mailing list)
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")

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

> File.makepath is also a sysnonym.

Regards, Daniel
Cfdeff3ac35010e4de8f85d954f24f4a?d=identicon&s=25 damphyr (Guest)
on 2005-11-21 23: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
8d6f5daee16e380ce0ac00395b417fb6?d=identicon&s=25 uval (Guest)
on 2005-11-21 23: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
Eba32a4bc6f1a4f60b434b7cae0715de?d=identicon&s=25 rascal1182 (Guest)
on 2005-11-21 23:31
(Received via mailing list)
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 :)

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")
---

...
Eba32a4bc6f1a4f60b434b7cae0715de?d=identicon&s=25 rascal1182 (Guest)
on 2005-11-21 23:39
(Received via mailing list)
On 11/21/05, Daniel Schüle <uval@rz.uni-karlsruhe.de> 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.