AssetDatabase.GetSubFolders(path) how to use?

I’ve been trying to figure out how to use the AssetDatabase.GetSubFolders(); function works with no luck.

The first thing I’m trying is to get all the subfolders of the Assets folder like this: string[] folders = AssetDatabase.GetSubFolders("Assets"); but with no luck.

I get an array of size zero and I can’t for the life of me figure out how to use this function. I’ve attempted googling but to no avail. Can anyone give me some directions here? Thanks!

Like you can read in the documentation of AssetDatabase.GetSubFolders that you have to pass a relative path an absolute path and not a relative path. GetSubFolders seems to just wrap the System.IO functions to get the folder information.

edit: Update
Since Unity 2017.1.3 GetSubFolders now requires a relative path, relative to the project folder. So an asset path has to start with Assets/.

Also keep in mind that the AssetDatabase class is an editor class and can’t be used at runtime. So you can only use them in editor script and not in MonoBehaviours.

“How to use it” is perfectly explained in the docs. If you have further problems you should tell us “for what purpose” you want to use that method and include your not working code…

As shown in the documentation, the AssetDatabase.GetSubFolders() method DOES use a relative path, a common mistake however is to leave a trailing “/”, which should not be provided.

Example correct usage: AssetDatabase.GetSubFolders("Assets/Resources/Textures");

Example INCORRECT usage: AssetDatabase.GetSubFolders("Assets/Resources/Textures/");