Skip to content

Instantly share code, notes, and snippets.

@pcarrier
Created June 27, 2011 16:05
Show Gist options
  • Save pcarrier/1049160 to your computer and use it in GitHub Desktop.
Save pcarrier/1049160 to your computer and use it in GitHub Desktop.
recursive_mkdir.rb
def self.mkdir_p(path)
path_acc = ''
path = File.join Dir.pwd, path if path[0] != ?/
path.split(File::SEPARATOR).grep(/./).collect do |name|
path_acc += File::SEPARATOR+ name
end.each do |dir|
begin Dir.mkdir(dir) rescue Errno::EEXIST end
end
end
@pcarrier
Copy link
Author

Ah ah in Ruby too.
Well that was fun to write anyway.

require 'ftools'
File.makedirs ("/path/that/exists/or/not")

@Daenyth
Copy link

Daenyth commented Jun 28, 2011

Indeed. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment