Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 JoeW97 · Nov 18, 2013 at 08:16 AM · assetspathfolder

How to find a path to a folder in the Assets folder?

How do I find the path to 'MyFolder' somewhere deep within the Assets folder? I've searched the Directory and AssetDatabase docs but can't find a way.

The closest is Directory.GetFiles(path), but that only lists the files within one given path.

Thanks

Comment
Add comment · Show 4
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 KiraSensei · Nov 18, 2013 at 10:35 AM 0
Share

Do you know the entire exact path ? or do you want to search it ?

Personnally, I offered the choice to users to play their own music while they play, and they put their music files in a specific folder, which I access with :

 var musicFolder:DirectoryInfo = new DirectoryInfo(Application.dataPath + "/$$anonymous$$usic");

Here are $$anonymous$$SDN doc and Unity doc I used to make this.

avatar image JoeW97 · Nov 18, 2013 at 10:50 AM 0
Share

Thanks, but I want to find the path. I know the folder exists, but it's possible the user has moved it. The danger with your method is that it could return null if someone moves the folder.

avatar image KiraSensei · Nov 18, 2013 at 11:00 AM 0
Share

Yes, but in the docs I gave you there is :

 DirectoryInfo.EnumerateDirectories

And I think this is what you are looking for. Then you need to combine this with the other stuff (Application.dataPath to have the "root" folder).

EDIT : here

avatar image JoeW97 · Nov 18, 2013 at 11:40 AM 0
Share

Thanks, that looked like a solution, but trying to use EnumerateDirectories gives an error: "`System.IO.DirectoryInfo' does not contain a definition for `EnumerateDirectories' ". Also, searching for EnumerateDirectories here returns no results. maybe Unity haven't implemented this? Are you able to call it successfully?

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by $$anonymous$$ · Nov 18, 2013 at 11:57 AM

You want to use Directory.GetDirectories() or Directory.GetFiles()

http://msdn.microsoft.com/en-us/library/c1sez4sc(v=vs.110).aspx http://msdn.microsoft.com/en-us/library/07wt70x2(v=vs.110).aspx

You can create a recursive function if necessary to get to the deepest subdirectory level if necessary.

You can also use string substitution with string.Replace() to convert those paths into asset paths relative to the Assets directory.

I hope this helps!

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 KiraSensei · Nov 18, 2013 at 12:24 PM 0
Share

"EnumerateDirectories" handles by itself the recursivity.

avatar image JoeW97 · Nov 18, 2013 at 12:29 PM 0
Share

As per previous comment, EnumerateDirectories returns an error in Unity. Is it $$anonymous$$icrosoft only?

avatar image KiraSensei · Nov 18, 2013 at 12:30 PM 0
Share

How did you use it ? (sorry, but I can't test it myself right now :) )

avatar image JoeW97 · Nov 18, 2013 at 12:47 PM 0
Share
 DirectoryInfo info = new DirectoryInfo(Application.dataPath);
 var dirs = info.EnumerateDirectories();

But, YAY!, looking through the $$anonymous$$SDN docs I found a solution using GetFiles() that works:

 string[] allPaths = Directory.GetFiles(Application.dataPath, "*", SearchOption.AllDirectories);


(That's using the global path, but easy to start from any directory)

avatar image KiraSensei · Nov 18, 2013 at 01:57 PM 0
Share

EnumerateDirectories takes a string as argument I think

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

18 People are following this question.

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

Related Questions

Does DirectoryInfo GetFiles work on Android ? 2 Answers

How To Refresh Resources Folder in Build? 1 Answer

Loading a ScriptableObject at Runtime. 1 Answer

Unable to Drag and Drop Folder/Assets into "Project" editor window. 2 Answers

Get UnityEngine.Object reference to folder in project from folder path 2 Answers


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