Getting array of assets in a directory?

I’m writing an editor tool, and would like to create a GUILayout.SelectionGrid with an array built with names of ScriptableObjects found in a specific directory.

Basically, I’m creating a UI to create/edit/delete ScriptableObjects in a database system I’m building.

Is there a way to get a list of SO’s from a directory, just of the file names, sorted by creation date? Not finding very much in the Unity docs for this sort of thing. Thank you for your time!

You’ll need to combine Unity’s asset management through the AssetDatabase and regular C# file IO for the creation date and other details.

First find your list of SOs GUIDs with AssetDatabase.FindAssets: Unity - Scripting API: AssetDatabase.FindAssets

Convert them to relative paths with AssetDatabase.GUIDToAssetPath: Unity - Scripting API: AssetDatabase.GUIDToAssetPath

Asset Database paths are relative, so you’ll need to convert them to absolute paths for File IO. You can use Application.dataPath to find the full path to the Assets folder in the editor, and then do some string manipulation since both paths will have “Assets” in them: Unity - Scripting API: Application.dataPath

Then for your creation dates, you have regular file IO using the absolute paths you constructed in the previous step: File.GetLastWriteTime Method (System.IO) | Microsoft Learn (last modified) or File.GetCreationTime Method (System.IO) | Microsoft Learn (creation)

1 Like

Thank you very much for the help! I got it mostly sorted out, thanks to your links :slight_smile:

1 Like