9

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.

akostadinov
  • 17,364
  • 6
  • 77
  • 85
ricardocaldeira
  • 679
  • 2
  • 11
  • 20
  • 5
    Seems pretty clear what the question is here, and it has quite a clear answer. Closing it seems a bit OTT. – Lee Winder Sep 19 '14 at 10:15
  • Duplicate of: http://stackoverflow.com/questions/3686032/how-to-create-directories-recursively-in-ruby – Tom Hale Nov 08 '16 at 11:10

2 Answers2

20

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

John
  • 29,546
  • 11
  • 78
  • 79
4

Is this what you're looking for?

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

mkpath is an alias of mkdir_p.

weakish
  • 28,682
  • 5
  • 48
  • 60
Brandan
  • 14,735
  • 3
  • 56
  • 71