[ACCEPTED]-What is the neatest way to split out a Path Name into its components in Lua-lua-patterns
Accepted answer
Here is an improved version that works for 3 Windows and Unix paths and also handles 2 files without dots (or files with multiple 1 dots):
= string.match([[/mnt/tmp/myfile.txt]], "(.-)([^\\/]-%.?([^%.\\/]*))$")
"/mnt/tmp/" "myfile.txt" "txt"
= string.match([[/mnt/tmp/myfile.txt.1]], "(.-)([^\\/]-%.?([^%.\\/]*))$")
"/mnt/tmp/" "myfile.txt.1" "1"
= string.match([[c:\temp\test\myfile.txt]], "(.-)([^\\/]-%.?([^%.\\/]*))$")
"c:\\temp\\test\\" "myfile.txt" "txt"
= string.match([[/test.i/directory.here/filename]], "(.-)([^\\/]-%.?([^%.\\/]*))$")
"/test.i/directory.here/" "filename" "filename"
> return string.match([[c:\temp\test\myfile.txt]], "(.-)([^\\]-([^%.]+))$")
c:\temp\test\ myfile.txt txt
This seems to do exactly what you want.
0
There is a few string to table functions 4 there, split "\" as \ cant be 3 in a folder name anyway so you'll end up 2 with a table with index one being the drive 1 and the last index being the file.
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.