add filename extraction

This commit is contained in:
Folkert Kevelam 2024-10-12 18:05:18 +02:00
parent d30a0e462b
commit e706a75645

View File

@ -106,7 +106,23 @@ function path.Walk_Up( P )
return string.sub(P, 1, #P - slash_first_idx + 1)
end
function path.Get_File( P )
local rev = string.reverse(P)
local start = 1
local slash_first_idx, _ = string.find(rev, "/", start, true)
return string.sub(P, #P - slash_first_idx + 2)
end
function path.Get_Filename( File )
local dot_first_idx, _ = string.find(File, ".", 1, true)
return string.sub(File, 1, dot_first_idx - 1)
end
function path.Generate_Dir_Walk( Base, Descend_List )
Descend_List = Descend_List or {}
local Descend_Length = #Descend_List
local i = -1
@ -123,18 +139,11 @@ function path.Generate_Dir_Walk( Base, Descend_List )
if i == 0 then
return Base_Dir
elseif i <= Descend_Length then
return Base_Dir .. Descend_List[i]
return Base_Dir .. Descend_List[i] .. "/"
end
end
return Inner
end
print(path.Common_Root("/home/folkert/Documents/Projects","/home/folkert/Downloads/sub/sub2/sub3/sub4/hello.txt"))
print(path.Get_Ext("/home/folkert/Documents/projects.wo.cp", {"o.cp"}))
for x in path.Generate_Dir_Walk("/home/folkert/", {"include", "src"}) do
print(x)
end
return path