Mkdirs function?


#1

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


#2

piece of cake :slight_smile:

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

mkdirs “dir1”, “dir2” , “dir3”


#3

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.


#4

Rob R. wrote:


File.makepath is also a sysnonym.

and mkdir_p :slight_smile:
V.-


http://www.braveworld.net/riva


#5

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


#6

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


#7

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 :slight_smile:

mkdir_p is not in ftools. It is in FileUtils. It is
Recommended™ 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")


#8

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.


#9

Hi

Damphyr wrote:

require ‘ftools’

File.makedirs ("/path/that/does/not/exist")

File.makepath is also a sysnonym.

and mkdir_p :slight_smile:

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 methodmkdir_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 :slight_smile:

Regards, Daniel