mkdirs function?

D

Daniel Schüle

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
 
P

Pete

piece of cake :)

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

mkdirs "dir1", "dir2" , "dir3"
 
D

Daniel Schüle

Hi
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
 
D

Damphyr

Daniel said:
Rob Rypka wrote:
=20
=20
=20
thx, that's what I looked for
I expected it to be a method of Dir
=20
They're actually definedd in module FileUtils.
V.-

--=20
http://www.braveworld.net/riva

____________________________________________________________________
http://www.freemail.gr - =E4=F9=F1=E5=DC=ED =F5=F0=E7=F1=E5=F3=DF=E1 =E7=EB=
=E5=EA=F4=F1=EF=ED=E9=EA=EF=FD =F4=E1=F7=F5=E4=F1=EF=EC=E5=DF=EF=F5.
http://www.freemail.gr - free email service for the Greek-speaking.
 
R

Rob Rypka

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.
 
R

Rob Rypka

irb(main):070:0> File.makedirs
=3D> []
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 necessa=
ry.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,197
Messages
2,571,040
Members
47,634
Latest member
RonnyBoelk

Latest Threads

Top