Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create subdirectories in Ruby [closed]

Tags:

ruby

I want to create a sub-directory of a directory that does not exist like: /foo/bar

I tried:

Dir.mkdir("foo/bar")

but this does not work.

like image 274
ricardocaldeira Avatar asked Aug 15 '12 01:08

ricardocaldeira


2 Answers

If you are trying to create a directory and its parent directories, you want to use FileUtils.mkdir_p instead.

like image 84
John Avatar answered Nov 17 '22 23:11

John


Is this what you're looking for?

require 'fileutils'
FileUtils.mkpath('/foo/bar')

mkpath is an alias of mkdir_p.

like image 36
Brandan Avatar answered Nov 17 '22 21:11

Brandan