Lua - Neatest way to split out a Path Name into its components Code Example

The code for Neatest way to split out a Path Name into its components

= 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"
Code by IncludeHelp, on January 2, 2023 20:37
Reference: stackoverflow

Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.