Module: Dir::MakeDirs
- Defined in:
- lib/vex/base/filesystem/make_dirs.rb
Instance Method Summary collapse
- #exists?(path) ⇒ Boolean
- #mkdirs(path) ⇒ Object
- #rmdirs(path) ⇒ Object
- #tmp(do_unlink = true, &block) ⇒ Object
Instance Method Details
#exists?(path) ⇒ Boolean
2 3 4 5 6 7 8 |
# File 'lib/vex/base/filesystem/make_dirs.rb', line 2 def exists?(path) begin Dir.open(path) && true rescue Errno::ENOENT, Errno::ENOTDIR false end end |
#mkdirs(path) ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'lib/vex/base/filesystem/make_dirs.rb', line 10 def mkdirs(path) paths = path.split("/") paths.each_with_index do |path, idx| p = paths[0..idx].join("/") next if p.empty? # This is root next if exists?(p) mkdir(p) end end |
#rmdirs(path) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/vex/base/filesystem/make_dirs.rb', line 20 def rmdirs(path) Dir.glob("#{path}/**/*", File::FNM_DOTMATCH).sort.reverse.each do |file| if File.directory?(file) next if file =~ /\/\.\.?$/ Dir.rmdir(file) else File.unlink(file) end end Dir.rmdir(path) end |