splitpath
function splitpath( path ) --> tab
Description
Splits a path into its single elements.
Parameters
- path
-
String path that should be split.
Return Values
- tab
-
String path elements.
Code
--ZFUNC-splitpath-v1 local function splitpath( path ) --> tab local tab = {} for token in string.gmatch( path, "[^/]+" ) do if #token > 0 then table.insert( tab, token ) end end return tab end return splitpath
Examples
local t = require( "tapered" ) local splitpath = require( "splitpath" ) t.same( { "a", "b", "c" }, splitpath( "a/b/c" ) ) t.same( { "a", "b", "c" }, splitpath( "a/b/c/" ) ) t.same( { "a", "b", "c" }, splitpath( "/a/b/c" ) ) t.same( { "c:", "a", "b", "c" }, splitpath( "c:/a/b/c" ) ) t.done()