-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutil.lua
36 lines (28 loc) · 822 Bytes
/
util.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
local M = {}
function M.path_basename(string_)
local LUA_DIRSEP = string.sub(package.config,1,1)
string_ = string_ or ''
local basename = string.gsub (string_, '[^'.. LUA_DIRSEP ..']*'.. LUA_DIRSEP ..'', '')
basename = string.gsub(basename, "(.+)%..+$", "%1")
print("pathbase name is "..basename)
return basename
end
function M.file_basename(path)
local file = string.gsub(path, "^.*[/\\](.+)$", "%1")
local name = string.gsub(file, "^(.+)%..+$", "%1")
print("file base name is "..name)
return name
end
function M.read_file(path)
local handle = io.open(path, "r")
local ret = handle:read("*a")
handle:close()
return ret
end
function M.write_file(path, data, mode)
local handle = io.open(path, mode)
handle:write(data)
handle:close()
print("dump to "..path.." file")
end
return M