[Python] get current folder name in World Outliner

Currently, I am trying to get the selected folder name in World Outliner in Unreal Level Editor.
I did finally get the actor by folder path, but I actually want to get the folder name itself by selecting it.
Is there anyway to do this by Python?

Hello, @Pilo_Gustinman

To get the folder name of a selected item in Unreal’s World Outliner using Python:

Python

import unreal

Get the selected actors

selected_actors = unreal.EditorUtilityLibrary().get_selected_actors()

Check if any actors are selected

if selected_actors:
# Get the folder path of the first selected actor
folder_path = selected_actors[0].get_folder_path()

# Extract the folder name
folder_name = folder_path.split('/')[-1] if folder_path else 'No Folder'

print(f"Folder: {folder_name}")

Hope this info will help you.
Best Regard,
geraldine198