How to add a folder to a selection?

Hi there,
I would like to know if there’s a way to add a folder from the Project panel to a selection. I know that I can add whatever object I want to the selection by using Selection.object (and also there are many answers like this one and this other one). What I haven’t been able to find is a way to “select a folder” from the Project panel. Any ideas?
The reason is that I need to adapt some AssetBundle generation code that relays on selecting folders in the Project panel and I want to emulate that with code. Is it possible?
Thanks.

So, yeah, I managed to make it work just by getting a reference to the asset path as if it was a simple object.

UnityEngine.Object obj = AssetDatabase.LoadAssetAtPath("Assets/MyFolder", typeof(UnityEngine.Object));
UnityEngine.Object[] selection = new UnityEngine.Object[1];
selection[0] = obj;
Selection.objects = selection;

Not pretty (as I get some warnings when creating the assetbundle) but it works.

2 Likes

AssetDatabase.OpenAsset(folderAssetObject);

Or
Selection.activeObject = folderAssetObject;
EditorGUIUtility.PingObject(folderAssetObject);