restructure
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
local strip_path = {}
|
||||
|
||||
--获取路径
|
||||
function strip_path.strip_filename(filename)
|
||||
return string.match(filename, "(.+)/[^/]*%.%w+$") --*nix system
|
||||
--return string.match(filename, “(.+)\\[^\\]*%.%w+$”) — windows
|
||||
end
|
||||
|
||||
--获取文件名
|
||||
function strip_path.strip_path(filename)
|
||||
return string.match(filename, ".+/([^/]*%.%w+)$") -- *nix system
|
||||
--return string.match(filename, “.+\\([^\\]*%.%w+)$”) — *nix system
|
||||
end
|
||||
|
||||
--去除扩展名
|
||||
function strip_path.strip_extension(filename)
|
||||
local idx = filename:match(".+()%.%w+$")
|
||||
if(idx) then
|
||||
return filename:sub(1, idx-1)
|
||||
else
|
||||
return filename
|
||||
end
|
||||
end
|
||||
|
||||
--获取扩展名
|
||||
function strip_path.get_extension(filename)
|
||||
return filename:match(".+%.(%w+)$")
|
||||
end
|
||||
|
||||
-- Test strip_path module
|
||||
--local paths = "/use/local/openresty/nginx/movies/fffff.tar.gz"
|
||||
--print (strip_path.strip_filename(paths))
|
||||
--print (strip_path.strip_path(paths))
|
||||
--print (strip_path.strip_extension(paths))
|
||||
--print (strip_path.get_extension(paths))
|
||||
|
||||
return strip_path
|
||||
Reference in New Issue
Block a user