So there are a few ways to do it. Your suggestion is not a great idea, and highly inefficient, but I will post the code here for educational purposes (while telling you never to use this):
func _ready():
var items = find_all_items(get_tree().root, [])
for item in items:
print(item.name)
func find_all_items(node, list) :
var children = node.get_children()
for child in children:
if child is Item:
list.append(child)
for child in children:
find_all_items(child, list)
return list
One other way is to use groups. You can add all your items to a group called Item. You can do this by clicking on the Node tab on the far right and then click Groups and add a group called Item. This is better because there is less code and it should be more optimized in the engine (meaning it will be faster).
var items = get_tree().get_nodes_in_group("Item")
for item in items:
print(item.name)
However, this is still not a good idea. Because after you get the items (which could be a list of dozens or hundreds of items in a large game), you will need to do distance or collision checks on each one, which is usually one of the most computationally expensive calls you can make in a game. So this will be horribly slow. The list generation will be faster than the first method, but both suffer from manual distance checking, so will not scale to a real game, and should not be used unless it is a small demo or limited type of game.
What you want to do is use the physics and collision functions that are included with Godot. This is the main reason to use an off-the-shelf engine in the first place, so you can take advantage of highly optimized C++ written by experts and not cobble together inefficient solutions yourself (wasting your time, and making the game slow and buggy). There are many ways to do this in Godot, like using collision bodies, areas, ray casts, etc. There is no right answer here, as it will depend on your game.
However, if the items don't need physics, then using Area2D or Area would probably be best. These are fairly cheap, and you can detect overlap easily. This is the code to get the mouse over on an Area2D (and you can easily get clicks or whatever you want). This is the easiest and fastest method IMO.
extends Area2D
func _ready():
connect("mouse_entered", self, "mouse_enter")
func mouse_enter():
print(self.name)