Module: KFile

Defined in:
lib/file/kfile.rb

Class Method Summary collapse

Class Method Details

.clear(dir) ⇒ Object



8
9
10
# File 'lib/file/kfile.rb', line 8

def self.clear(dir)
	FileUtils.rm_r Dir.glob("#{dir}/*")
end

.copy(src, dest) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
# 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) ⇒ Object



4
5
6
# File 'lib/file/kfile.rb', line 4

def self.delete(dir)
	FileUtils.rm_r(dir) if File.exists? dir
end

.list(dir, recursive = true, &proc) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# 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') ⇒ Object



44
45
46
47
48
# 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