There's sort of a way to do it.
Parse the string into individual table indexes.
local tbl = {"somedirectory","subdirectory","foo"}
and then loop through that table looking at the lookup table to see if you've got your value.
local fileTable = {
fileA = 'data',
dirA = {
data = 'stuff',
contents = {
subFileA = 'data',
subFileB = 'data',
},
},
fileB = 'data',
}
local function findFile(path)
--#Parse function here, I'm too lazy to make it
local foundValue = fileTable
for a,v in ipairs(tbl) do --#Loop through the numerical indices in order
if (foundValue[v]) then--#If it exists.
if (type(foundValue[v]) ~= "table") then --If it's not a table, and just an item
return foundValue[v], a == #tbl and true or false --#first part: return the data. Second part: Tell them if this was the file we're looking for, or we're at a dead end.
else --#Then we've got another table
foundValue = foundValue[v] --#Lets go into that table, since that's part of our path
end
else --#Our file doesn't exist.
return nil,nil --#Return absolutely nothing
end
end
return foundValue,true --#If our last value was a table, we're not gonna return it, so we need to do it here.
end
local fileData, madeToEnd = findFile("dirA/contents/subFileA") --#FileData will hold your file/directory (Directory if we ended on contents at this point)
--#or it will have nil, if it couldn't find your file.
--#MadeToEnd will have a value of true,false,or nil. True means it looped as far as it could, and found a file or directory at the last entry: subFileA here.
--#False means it found a value BEFORE the last one, if we did dirA/data/subFileA we would get the stuff from the data entry into fileData and this would be false.
--#Nil means well, it means that fileData was nil as well. Which means it didn't find the file you were looking for.