Class: Dir
Class Method Summary collapse
-
.make_dirs(path) ⇒ Object
creates multiple directories.
-
.prep_dir(path) ⇒ Object
if a directory exists, it deletes everything in it, otherwise it creates the directory.
Class Method Details
.make_dirs(path) ⇒ Object
creates multiple directories
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/m_dir.rb', line 5 def self.make_dirs(path) dir_names = path.split('/') new_path="" dir_names.each do |x| new_path = new_path << x << '/' if !File.directory?(new_path) Dir.mkdir(new_path) end end end |
.prep_dir(path) ⇒ Object
if a directory exists, it deletes everything in it, otherwise it creates the directory
18 19 20 21 22 23 24 |
# File 'lib/m_dir.rb', line 18 def self.prep_dir(path) if File.directory?(path) Dir.foreach(path) {|x| File.delete(path + x) unless File.directory?(path + x)} else Dir.make_dirs(path) end end |