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
0
Question by rsud · Dec 27, 2014 at 05:20 AM · listfunctionfile

How to get the contents of a directory?

I want to get a list of files in a sub directory under the Resources folder from a c# script in Unity.

I am looking at the File and Directory functions but what they do is minimal.

How would I do this?

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 Eric5h5 · Dec 27, 2014 at 05:48 AM 1
Share

The Resources folder does not exist in a build. Unless you're doing this exclusively in the editor, it will not work.

avatar image rsud · Jan 02, 2015 at 04:10 AM -1
Share

Third time I am posting this...

I want to load a set of jpg files in several directories into and array of Texture[].

I was expecting that the Resources dir to be available as a root folder and I would create folders under Resources and place jpg texture files in the folders I create.

The number of jpg files in the directories will vary.

Thanks for the 'using System.IO' tidbit. This may be what I was missing (I'm new to c#) because Directory was undefined.

But I guess I have a new issue in that the Resources folder only exists within Unity editor.

How can I have a directory that holds files that is part of the Unity game once I deploy it to run on a device (like an iPhone)?

1 Reply

· Add your reply
  • Sort: 
avatar image
2

Answer by jgodfrey · Dec 27, 2014 at 05:24 AM

You probably want Directory.GetFiles()

There are lots of folder / file methods available in .NET/Mono...

Comment
Add comment · Show 6 · 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 rsud · Dec 27, 2014 at 05:33 AM 0
Share

Can I call Directory.GetFiles() from a C# script in Unity? Do you perhaps have some sample code?

avatar image jgodfrey · Jan 02, 2015 at 03:12 AM 1
Share

Hmmm... I can't seem to add a new answer, but...

I'm not sure what's wrong with my original answer. The following code will retrieve all *.TXT files from the C:\ folder. Though, you'll need to add a 'using System.IO' to have access to the Directory class.

 void Start()
 {  
     foreach (string file in Directory.GetFiles(@"c:\", "*.txt"))
     {
         Debug.Log(file);
     }
 }
avatar image Eric5h5 · Jan 02, 2015 at 03:16 AM 1
Share

Nothing was wrong with your answer, although the OP should state what the actual intent of the question is, since as I mentioned there is no Resources folder as such in a build.

avatar image jgodfrey · Jan 02, 2015 at 03:22 AM 0
Share

@Eric5h5 - Agreed on all counts. Though, I thought there was more explanation here a few $$anonymous$$utes ago, but I don't see it now (maybe OP deleted).

avatar image rsud · Jan 02, 2015 at 02:11 PM 0
Share

I want to load a set of jpg files in several directories into and array of Texture[].

I was expecting that the Resources dir to be available as a root folder and I would create folders under Resources and place jpg texture files in the folders I create.

The number of jpg files in the directories will vary.

Thanks for the 'using System.IO' tidbit. This may be what I was missing (I'm new to c#) because Directory was undefined.

But I guess I have a new issue in that the Resources folder only exists within Unity editor.

How can I have a directory that holds files that is part of the Unity game once I deploy it to run on a device (like an iPhone)?

$$anonymous$$y other choice would appear to be to make all my texture holding variables 'public texture' and drop the texture into them in the editor. But this is inefficient when I will have a large number of texture files.

$$anonymous$$y use here is that I will have varied planet textures (space game) that will applied to a sphere. I expect 100's of stars with 1 to 12 planets each. I will have varied texture jpg files (maybe a 100 or so) with the planets surface.

Show more comments

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

28 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

A node in a childnode? 1 Answer

How can i get a function to return 2D List? 0 Answers

WWW file:// protocol to list a directory 1 Answer

Variable will not change? 1 Answer

Function call is not working 0 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