I'm trying to use the following code snippet:
Code: Select all
function SplitFilename(strFilename)
-- Returns the Path, Filename, and Extension as 3 values
if lfs.attributes(strFilename,"mode") == "directory" then
local strPath = strFilename:gsub("[\\/]$","")
return strPath.."\\","",""
end
return strFilename:match("(.-)([^\\/]-([^\\/%.]+))$")
end
For example, fed "C://example.com/path/image_without_extension"
it returns
Code: Select all
C://example.com/path/
image_without_extension
image_without_extension
returns
Code: Select all
C://example.com/path/
image_without_extension.tif
tif
the complete path
the filename without trailing . or extension
the extension
so e.g.
Code: Select all
C://example.com/path/
image_without_extension
tif
Code: Select all
C://example.com/path/
image_without_extension
nil
Anyone suggest how I can modify it -- or point me to a utility for creating Lua patterns (I have one for all flavours of regex, but can't find one for patterns)