Files
resty_functions/strip_path.lua
T
XiaoLi 6580d73d31 add upyun operation (#45)
* add upyun operation

* uft8 encoder fail

* calculate authorization ok

* clean up

* clean up
2022-01-13 19:37:01 +08:00

37 lines
1.0 KiB
Lua

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