module KFile

Public Class Methods

clear(dir) click to toggle source
# File lib/file/kfile.rb, line 8
def self.clear(dir)
        FileUtils.rm_r Dir.glob("#{dir}/*")
end
copy(src,dest) click to toggle source
# File lib/file/kfile.rb, line 12
def self.copy(src,dest)
        return if !File.exists? src
        if File.directory? src
                Dir.mkdir(dest) if !File.exist? dest
                Dir.foreach(src) do |path|
                        if path !="." and path !=".."
                                copy(src+"/"+path,dest+"/"+path)
                        end
                end
        else
                FileUtils.cp(src,dest)
        end
end
delete(dir) click to toggle source
# File lib/file/kfile.rb, line 4
def self.delete(dir)
        FileUtils.rm_r(dir) if File.exists? dir
end
list(dir,recursive = true) { |full_path| ... } click to toggle source
# File lib/file/kfile.rb, line 26
def self.list(dir,recursive = true,&proc)
        return if !File.exists? dir
        if File.directory?(dir)
                Dir.foreach(dir) do |path|
                        if path !="." && path !=".."
                                full_path = dir + "/" + path
                                if recursive
                                        list(full_path,recursive,&proc)
                                else
                                        yield full_path
                                end
                        end
                end
        else
                yield dir
        end
end
read(file_path,encoding = 'utf-8') click to toggle source
# File lib/file/kfile.rb, line 44
def self.read(file_path,encoding = 'utf-8')
        File.open(file_path,"r:#{encoding}"){|f|
                return f.read
        }
end