function stripfilename(filename)
return string.match(filename, "(.+)/[^/]*%.%w+$") --*nix system
--return string.match(filename, “(.+)[^]*%.%w+$”) — windows
end
--获取文件名
function strippath(filename)
return string.match(filename, ".+/([^/]*%.%w+)$") -- *nix system
--return string.match(filename, “.+([^]*%.%w+)$”) — *nix system
end
--去除扩展名
function stripextension(filename)
local idx = filename:match(".+()%.%w+$")
if(idx) then
return filename:sub(1, idx-1)
else
return filename
end
end
--获取扩展名
function getextension(filename)
return filename:match(".+%.(%w+)$")
end
local paths = "/use/local/openresty/nginx/movies/fffff.tar.gz"
print (stripfilename(paths))
print (strippath(paths))
print (stripextension(paths))
print (getextension(paths))
[[email protected] cdnlua]# lua testfile.lua
/use/local/openresty/nginx/movies
fffff.tar.gz
/use/local/openresty/nginx/movies/fffff.tar
gz
声明: 此文观点不代表本站立场;转载须要保留原文链接;版权疑问请联系我们。