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 BadAssGames · Oct 08, 2014 at 03:39 AM · androidsavingdirectoryfilebrowser

Do I need an Android Equivalent to DirectoryInfo.GetFiles()?

I have a custom save/load interface for my game. I serialize all my data into .dat files and deserialize them when I load the data.

I'm using this code to get the directory information where all my save games are being stored:

 enter code here    //This function gets a list of all the files
     public FileInfo[] GetDirectoryList()
     {
 
         string path = Application.persistentDataPath + savePath;
         DirectoryInfo info = new DirectoryInfo(path);
         FileInfo[] fileInfo = info.GetFiles();
 
         return fileInfo;
     }


It works perfectly on PC, but on Android it does not return anything. Nothing displays. When I use Astro File Viewer (external file browser) I can see that the save files are being placed where they should be. Is there a different method I should be using for Android? Why is this code not returning anything?

Also, to be clear, I have enabled "Write Access: External SD Card" in the Player Settings.

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 zaid87 · Oct 08, 2014 at 04:49 AM 0
Share

Just wondering, why not use PlayerPrefs ins$$anonymous$$d for saving/loading? It will automatically sets the file depending on the platform the game is run on.

avatar image BadAssGames · Oct 08, 2014 at 05:07 AM 0
Share

I have large lists of data that need to be kept track of (hundreds of variables). $$anonymous$$anually setting a player pref for each one would be too time consu$$anonymous$$g. Additionally, this generates a single file which can be transferred from machine to machine, which is ideal for my needs

Additionally, my method allows a player to easily store multiple save profiles.

1 Reply

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

Answer by BadAssGames · Oct 08, 2014 at 07:04 AM

After a comically lengthy amount of time, I discovered the problem. This was one of those bugs that makes you pull your hair out, just to find out that you forgot a semicolon somewhere.

The solution was this: I used a "\" in my pathing. Switching it to "/" solved it. I don't know why.

My final path now looks like this: Application.persistentDataPath + "/" + filename;

While this issue is now solved, I would appreciate anyone who can explain this to me.

Comment
Add comment · Show 2 · 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 Landern · Oct 08, 2014 at 07:19 AM 0
Share

Hrm, use Path.Combine(System.IO namespace) for stuff like that, it will put the directory separator in there for you.

If things are correct, then the Path.DirectorySeparatorChar that is used should ("SHOULD") resolve correct between windows('\') and un*x like systems('/')

avatar image Eric5h5 · Oct 08, 2014 at 08:02 AM 0
Share

Windows is the only OS that uses "\" ...everything else uses "/". Except you can just go ahead and always use "/" for the sake of consistency, including Windows builds, and it will work. Technically you can use "\" on Windows, but it can potentially lead to problems like this if you accidentally used it on other systems, so it's safer to always use "/".

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

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

Related Questions

Get file list from a directory on Android 4 Answers

how to instantiate saved objects back into game 1 Answer

How to save screenshots on Android with Unity and C#? 0 Answers

working on pc but not in phone 1 Answer

Download and saving .txt from server to Android 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