Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by Alex la kitteh · May 29, 2015 at 05:32 AM · assetdatabaseusage

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!

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Diet-Chugg · Jun 08, 2015 at 02:23 AM 0
Share

Having same problem. When I figure it out I'll post here.

avatar image zzhamzz · Nov 20, 2015 at 07:24 AM 0
Share

Doesn't seem to work for me either. Doesn't seem to work with absolute or relative paths. Any of the following lines will return a zero sized string array:

 string[] subs = AssetDatabase.GetSubFolders("C:/");
 string[] subs = AssetDatabase.GetSubFolders(Application.dataPath);
 string[] subs = AssetDatabase.getSubFolders("Assets");
 string[] subs = AssetDatabase.getSubFolders(".");
 string[] subs = AssetDatabase.getSubFolders("..");

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Bunny83 · Jun 08, 2015 at 03:58 AM

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...

Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Alex la kitteh · Jun 08, 2015 at 07:32 AM 0
Share

Thanks for the answer! I guess I should've formulated my question better. The docs did not have an example for how to use this function, only an explanation of what it does, therefore I asked here in the hopes someone had one. I will try with providing an absolute path ins$$anonymous$$d, which if I'm not entirely incorrect can be done using the AssetDatabase helper. I am attempting to check if a folder exists in the folder tree, and then if it does exist, save a file inside of it. The code was irrelevant to the question other than the very line of code I provided.

avatar image Alex la kitteh · Jun 08, 2015 at 07:41 AM 0
Share

I have done some researched and from what I have gathered, the relative path's should work according to this answer. Therefore I shouldn't be getting an array of size 0 when I try an get the subfolders of the Assets folder. Could it be because the script is executed in another folder and I need to change the path?

avatar image Torantulino · Aug 22, 2021 at 04:42 PM 0
Share

This answer is incorrect. You must provide a relative path, not an absolute one. This is shown in the docs through their working example of AssetDatabase.GetSubFolders("Assets");.

avatar image Eno-Khaon Torantulino · Aug 22, 2021 at 06:21 PM 1
Share

The example script wasn't included in Unity's scripting documentation until version 2020.1, seeing how version 2019.4 does not include the example. With this in $$anonymous$$d, the function has also clearly been changed at some point.

While AssetDatabase.GetSubFolders() uses a relative path now, it used an absolute path in a previous version.

Edit: Looking back further, the change itself was made between versions 2017.1 and 2017.2.

avatar image Bunny83 Eno-Khaon · Aug 22, 2021 at 10:41 PM 0
Share

Thanks, I've updated my answer with the relevant release notes of Unity 2017.1.3:

Asset Pipeline: AssetDatabase.GetSubfolders now returns paths correctly, and API documentation has been updated to reflect that it takes a relative path as an argument. (931944)


Thanks for narrowing down the version of the change ^^.

avatar image
0

Answer by Torantulino · Aug 26, 2021 at 04:42 PM

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/");

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Can I safely put a prefab asset into version control with Unity Free? 3 Answers

Save procedural mesh in the editor as asset. 2 Answers

AssetDatabase.ExportPackage not working 3 Answers

Ho do I find all scenes with a certain script on an GameObject 2 Answers

Settting Selection.activeObject to multiple items 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges