Making a "Path" System?

I’m trying to make a path system like in windows file explorer. Like “C:/Users/…/”. This is my code.

local init = {}

function check_folders(start)
	for _, v in pairs(start) do
		return v
	end
end

function init.run(orig_path)
	
	if typeof(orig_path) ~= "string" then
		warn("INIT: PATH TYPE IS NOT A STRING")
	end
	local path_new = string.lower(orig_path)
	local path = string.split(path_new, "/")
	if path[1] ~= 'CORE:' or path[1] ~= 'core:' then
		warn("INIT: UNKNOWN PATH START")
	end
	for i, v in pairs(path) do
		if not path[i-1]:FindFirstChild(path[i]) and check_folders(script.Parent.CORE) then
			warn("INIT: PATH UNKNOWN")
		else
			return path
		end
	end
end

return init

This is the folder.
aaa

Can you please be more specific? What are you trying to achieve?

A folder path system, already said. Read the code.

What is exactly your goal? What is not working? Please be more specific, I don’t even understand your code along with your goal.

use string.split() to get the different parts of the path, string.split("urmom/pro", "/") will split it using the slash character, if it can find any. So like damboi/pro will be split into splitresult[1] = damboi, splitresult[2] = pro
respectively.

When you use the script, I want you to be able to manipulate a folder via specifying a path with init.run. For example (refer to the imagine for the example), this:

local folder = init.run(“CORE:/test”)

folder:Destroy()

I’ve already done that. I need help referring the arguments of the “/” to the folders.

Very unique way of helping on the devforum LOL.

2 Likes

wdym, I am confused lol. Explain pls

For example, “CORE:/test”
I split the path into 2 arguments, CORE and test
I want to refer CORE to the head parent folder, and refer test to the test folder.
refer to the image

You should probably end the code here if it isn’t a string.

At the first iteration, it would error because you cannot index 0 in any tables, and two you’re referring the string only, not the instance. You should’ve use FindFirstChild() on testing the presence of the folder in the explorer tab. Why are you subtracting the index to 1 anyway? You should be taking the second index which should be +1, same thing goes to the same index inside the FindFirstChild().

I want to check if an argument in the path is a parent of the next arguments, if not, I’m going to output an error. So what do I do exactly?

First, test the presence of the parent. If it doesn’t return true, then error it.

Then, test the presence of the child and make sure it’s the child of that parent. No? Then error it.

Could you give me that code please?

Just saw your name, you’ve been on quite a few of my devforum posts. Nice to see you again, you’ve been a big help to me.

This is only example of code.

function init:run(path : string)
    path = path:split(":/") -- "C:/memes" --> ["C", "memes"]
    local parent = path[1]
    local testParentPresent = workspace:FindFirstChild(parent, true) -- true means it will search for descendants with that name.

    if testParentPresent then
        print("Parent found!")
        local testChildrenPresent = testParentPresent:FindFirstChild(path[-1])

        if testChildrenPresent then
            print("Child found!")
            return testChildrenPresent
        end
    end
end)

I just realized I could use FindFirstDescendant, and thank you.

But what if I want multiple paths? Example, CORE:/test/test2

Still works, I was struggling at that first, but I remember you can index an array backwards using negative numbers. So using path[-1], this will refer the last position in an array.

It doesn’t refer to the folder in workspace. I want to be able to manipulate the folder. ex., destroy it, change its parent, etc.

May I see the error? please provide screenshots.

image

image

image

Can I see your current init:run() code?