module Motion::FileUtils
Public Class Methods
cp(src, dest, options = {})
click to toggle source
# File lib/project/motion-fileutils.rb, line 104 def cp(src, dest, options = {}) error = Pointer.new(:object) m = NSFileManager.defaultManager if File.file?(dest) || !File.exists?(dest) raise Errno::ENOTDIR if src.is_a?(Array) && File.file?(dest) rm dest if File.file?(dest) r = m.copyItemAtPath src, toPath:dest, error:error #p error, r unless r else src = [src] unless src.is_a? Array src.each do |path| r = m.copyItemAtPath path, toPath:File.join(dest, File.basename(path)), error:error #p error, r unless r end end end
mkdir(dir, options = {})
click to toggle source
# File lib/project/motion-fileutils.rb, line 9 def mkdir(dir, options = {}) mkdir_with_intermediate(dir, false, options) end
mkdir_p(dir, options = {})
click to toggle source
# File lib/project/motion-fileutils.rb, line 14 def mkdir_p(dir, options = {}) mkdir_with_intermediate(dir, true, options) end
mv(src, dest, options = {})
click to toggle source
# File lib/project/motion-fileutils.rb, line 83 def mv(src, dest, options = {}) error = Pointer.new(:object) m = NSFileManager.defaultManager if File.file?(dest) || !File.exists?(dest) raise Errno::ENOTDIR if src.is_a?(Array) && File.file?(dest) rm dest if File.file?(dest) r = m.moveItemAtPath src, toPath:dest, error:error #p error, r unless r else src = [src] unless src.is_a? Array src.each do |path| r = m.moveItemAtPath path, toPath:File.join(dest, File.basename(path)), error:error #p error, r unless r end end end
Also aliased as: move
rm(list, options = {})
click to toggle source
# File lib/project/motion-fileutils.rb, line 25 def rm(list, options = {}) error = Pointer.new(:object) m = NSFileManager.defaultManager list = [list] unless list.is_a? Array list.each do |path| r = m.removeItemAtPath path, error:error #p error, r unless r end end
Also aliased as: remove
touch(list, options = {})
click to toggle source
# File lib/project/motion-fileutils.rb, line 63 def touch(list, options = {}) t = options[:mtime] created = nocreate = options[:nocreate] list = [list] unless list.is_a? Array list.each do |path| begin File.utime(t, t, path) rescue Errno::ENOENT raise if created File.open(path, 'a') { ; } created = true retry if t end end end
Private Instance Methods
cp(src, dest, options = {})
click to toggle source
# File lib/project/motion-fileutils.rb, line 104 def cp(src, dest, options = {}) error = Pointer.new(:object) m = NSFileManager.defaultManager if File.file?(dest) || !File.exists?(dest) raise Errno::ENOTDIR if src.is_a?(Array) && File.file?(dest) rm dest if File.file?(dest) r = m.copyItemAtPath src, toPath:dest, error:error #p error, r unless r else src = [src] unless src.is_a? Array src.each do |path| r = m.copyItemAtPath path, toPath:File.join(dest, File.basename(path)), error:error #p error, r unless r end end end
mkdir(dir, options = {})
click to toggle source
# File lib/project/motion-fileutils.rb, line 9 def mkdir(dir, options = {}) mkdir_with_intermediate(dir, false, options) end
mkdir_p(dir, options = {})
click to toggle source
# File lib/project/motion-fileutils.rb, line 14 def mkdir_p(dir, options = {}) mkdir_with_intermediate(dir, true, options) end
mkdir_with_intermediate(dir, intermediate, options = {})
click to toggle source
# File lib/project/motion-fileutils.rb, line 41 def mkdir_with_intermediate(dir, intermediate, options = {}) error = Pointer.new(:object) m = NSFileManager.defaultManager dir = [dir] unless dir.is_a? Array paths = [] dir.each do |path| r = m.createDirectoryAtPath path, withIntermediateDirectories:intermediate, attributes:nil, error:error paths << path if r #p error, r unless r end case paths.size when 0 nil when 1 paths.first else paths end end
mv(src, dest, options = {})
click to toggle source
# File lib/project/motion-fileutils.rb, line 83 def mv(src, dest, options = {}) error = Pointer.new(:object) m = NSFileManager.defaultManager if File.file?(dest) || !File.exists?(dest) raise Errno::ENOTDIR if src.is_a?(Array) && File.file?(dest) rm dest if File.file?(dest) r = m.moveItemAtPath src, toPath:dest, error:error #p error, r unless r else src = [src] unless src.is_a? Array src.each do |path| r = m.moveItemAtPath path, toPath:File.join(dest, File.basename(path)), error:error #p error, r unless r end end end
Also aliased as: move
rm(list, options = {})
click to toggle source
# File lib/project/motion-fileutils.rb, line 25 def rm(list, options = {}) error = Pointer.new(:object) m = NSFileManager.defaultManager list = [list] unless list.is_a? Array list.each do |path| r = m.removeItemAtPath path, error:error #p error, r unless r end end
Also aliased as: remove
touch(list, options = {})
click to toggle source
# File lib/project/motion-fileutils.rb, line 63 def touch(list, options = {}) t = options[:mtime] created = nocreate = options[:nocreate] list = [list] unless list.is_a? Array list.each do |path| begin File.utime(t, t, path) rescue Errno::ENOENT raise if created File.open(path, 'a') { ; } created = true retry if t end end end