用lua获取目录,文件名,扩展名
2012-06-11 22:56
204 查看
用lua获取目录,文件名,扩展名
很多时候我们需要从全路径中取得目录,文件名或者扩展名。办法有许多,看lua是怎么做的:–获取路径
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
refer to: http://lua-users.org/lists/lua-l/2010-07/msg00088.html
相关文章推荐
- windows平台C程序获取可执行程序路径及目录、文件名、扩展名
- C# 轻松获取路径中文件名、目录、扩展名等
- C# 轻松获取路径中文件名、目录、扩展名等
- C# 轻松获取路径中文件名、目录、扩展名等
- C# 获取路径中文件名、目录、扩展名等
- C# 获取文件名、目录、后缀、无后缀文件名、扩展名、根目录等
- C# 获取路径中,文件名、目录、扩展名等
- C# 轻松获取路径中文件名、目录、扩展名等
- C# 轻松获取路径中文件名、目录、扩展名等(有用)
- C# 轻松获取路径中文件名、目录、扩展名等
- PHP获取 ,根目录,当前文件路径,上层目录路径 ,文件名,扩展名
- lua 获取指定目录下指定后缀文件名
- C# 轻松获取路径中文件名、目录、扩展名等
- C# 获取路径中,文件名、目录、扩展名等
- C# 轻松获取路径中文件名、目录、扩展名等
- 获取当前目录下所有文件名(扩展名为qar)
- C# 获取路径中,文件名、目录、扩展名等
- lua 获取文件名和扩展名
- C# 轻松获取路径中文件名、目录、扩展名等
- MFC选择文件对话框、选择目录对话框、获取指定目录下文件名和个数