Explorer: Right click > Copy absolute path

One of the most tedious parts of scripting is writing out the full paths of my dependencies at the beginning of the script (WaitForChilds and everything included). Stuff like this:

local materialColor = require(game.ReplicatedStorage:WaitForChild("Util"):WaitForChild("MaterialColor"));

Now there’s already an option in the Game Explorer that lets you right click an asset and copy it’s path to the clipboard. I propose adding an option to the place Explorer that lets you right click it and copy it’s full path (from game) to the clipboard. Two options would be great: one that includes all the WaitForChilds and one that doesn’t.

19 Likes

this sounds like a studio feature.

but also, i’d like to see this feature.

1 Like

This is something that is more fitting of a plugin and not really something that needs to be built into studio. There is already a method that lets you get a path of an object in game. It’s called GetFullName(). However, it does not handle objects with spaces or punctuation in their names, nor can it do WaitForChilds. That being said it’s simple enough to write something that will do that for you.

local function addParentRecursive(object, t)
	if (object and object.Parent) then
		table.insert(t, object.Parent == game and "game" or object.Parent.Name);
		addParentRecursive(object.Parent, t);
	end;
end;

local function getPath(object, useWaitForChild)
	local t = {object.Name};
	addParentRecursive(object, t);
	local path = t[#t];
	if (useWaitForChild) then
		for i = #t-1, 1, -1 do
			path = path .. ":WaitForChild(\"" .. t[i] .. "\")";
		end;
	else
		for i = #t-1, 1, -1 do
			local name = t[i];
			if (name:match("[^%w_]+") or name:sub(1, 1):match("%d")) then
				path = path .. "[\"" .. name .. "\"]";
			else
				path = path .. "." .. name;
			end;
		end;
	end;
	return path;
end;

A test case for comparison:

Capture

print(script:GetFullName());
print(getPath(script, false));
print(getPath(script, true));

Output:

Workspace.Base_plate.Folder.1Script
game.Workspace.Base_plate.Folder["1Script"]
game:WaitForChild("Workspace"):WaitForChild("Base_plate"):WaitForChild("Folder"):WaitForChild("1Script")

I’m sure there are bugs of some sort in the code, but you get the general jist…

Having to write a print statement in the command line that includes the path to the object is kind of self-defeating. We can use Selection:Get() of course but selecting something in explorer and then copying and pasting a command from somewhere (probably an external text editor) and then copying and pasting the output into the script is almost as tedious.

Use a plugin button, a hot key, err whatever…

There’s no need to copy paste to the command line every time. Just click the button while selecting objects (or whatever) and print the paths to the output.