-- Obtain the path function stripfilename (filename) return string. match (filename ,"(. +)/[^/] * %. % W + $ ") -- * nix System -- Return string. match (filename, "(. +) \ [^ \] * %. % W + $ ")-windowsend -- get the function strippath (filename) return string. match (filename ,". +/([^/] * %. % W +) $ ") -- * nix System -- Return string. match (filename, ". + \ ([^ \] * %. % W +) $ ")-* nix systemend -- remove the extension function stripextension (filename) Local idx = filename: Match (". + () %. % W + $ ") if (idx) thenreturn filename: Sub (1, idx-1) elsereturn filenameendend -- get the extension function getextension (filename) return filename: Match (". + %. (% W +) $ ") endlocal paths ="/use/local/openresty/nginx/movies/fffff.tar.gz "Print (stripfilename (paths) print (strippath (paths )) print (stripextension (paths) print (getextension (paths ))
[Root @ localhost cdnlua] # Lua testfile. Lua
/Use/local/openresty/nginx/movies
Fffff.tar.gz
/Use/local/openresty/nginx/movies/fffff.tar
GZ