Creating a directory with File.makedirs

P

Peter Marks

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
 
P

Phil Meier

Peter said:
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/File.html). 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
 
E

Eric Hodel

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.
 

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,266
Messages
2,571,342
Members
48,018
Latest member
DelilahDen

Latest Threads

Top