[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Creating a directory with File.makedirs

Peter Marks

10/2/2007 5:12:00 AM

I am trying to create a directory in Rails with the following code:

File.makedirs '/folder/subfolder/'

However, I get the error "undefined method `makedirs' for File:Class".
Has makedirs been deprecated to something else?

Thanks,

peter
--
Posted via http://www.ruby-....

3 Answers

Phil Meier

10/2/2007 6:43:00 AM

0

Peter Marks schrieb:
> I am trying to create a directory in Rails with the following code:
>
> File.makedirs '/folder/subfolder/'
>
> However, I get the error "undefined method `makedirs' for File:Class".
> Has makedirs been deprecated to something else?
>
> Thanks,
>
> peter

makedir is a method defined in ftools (see
http://www.ruby-doc.org/core/classes...). Therefore - add
require 'ftools'
if you want to use this method.

Or even better use the corresponding method being defined in "FileUtils"
module.

BR Phil

Peter Marks

10/2/2007 6:51:00 AM

0

Phil Meier wrote:
> require 'ftools'

ah, of course. Thanks for helping a neub Phil :)
--
Posted via http://www.ruby-....

Eric Hodel

10/2/2007 8:18:00 AM

0

On Oct 1, 2007, at 23:51 , Peter Marks wrote:

> Phil Meier wrote:
>> require 'ftools'
>
> ah, of course. Thanks for helping a neub Phil :)

FileUtils is the preferred way now. ftools.rb says:

> # FileUtils contains all or nearly all the same functionality and
> more, and
> # is a recommended option over ftools
>
> # See the method descriptions below, and consider using FileUtils
> as it is
> # more comprehensive.

FileUtils.mkdir_p makes directories recursively.

--
Poor workers blame their tools. Good workers build better tools. The
best workers get their tools to do the work for them. -- Syndicate Wars