starwing / lpath

a OS specified path manipulation module for Lua

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Question about path.split()

andreypopp opened this issue · comments

Hello and thank you for the lpath library!

I have a question about usage of path.split() function.

I was trying to find a function to get a path's dirname and it seems path.split() does exactly that. The problem is that for the input "/a/b/ it results into "/a/b/", "" while I'd expect it to be "/a", "b/" so that I can pass "/a" to path.split() next.

My exact use case is to get a a list of parent paths out of some path:

/a/b/c
/a/b
/a
/

and it seems I need to manually strip the trailing "/" when using path.split() to achieve that. Am I missing some other utility function or usage pattern? Or maybe path.split() should so some path normalization (stripping the trailing /)?

I have add a new interface: path.trim() may help this usage:

local path = require "path"
local s = "/a/b/c/d/"

while s ~= "/" do
   local a = path.split(s)
   s = path.trim(a)
   print(s)
end

A new path.parent introduced for this usage.