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 ThisLove · Oct 11, 2020 at 12:21 AM · errorserializationdirectoryfilepath

Why is my file path invalid?

Ok, so I had a Unity project on my mac computer and tried transferring into a windows. I've tried just using the same file and then also transferring just the assets into a new project. Neither are working and both give me this error saying my directory is no good: "IOException: The directory name is invalid System.IO.Directory.CreateDirectoriesInternal (System.String path) (at :0) System.IO.Directory.CreateDirectory (System.String path) (at :0) SaveLoad.save[T] (T pyramid, System.String key, System.String fileName) (at Assets/Scripts/SaveLoad.cs:18)..."

This program works on my mac and thought my code was universal:

public static class SaveLoad { public static string fileType = ".jesus";

 public static void save<T>(T pyramid, string key, string fileName)
 {
     BinaryFormatter formatter = new BinaryFormatter();

     string path = Application.persistentDataPath + "/" + fileName + "/";
     Directory.CreateDirectory(path);
     FileStream stream = new FileStream(path + key + fileType, FileMode.Create);

     formatter.Serialize(stream, pyramid);
     stream.Close();
 }

 public static T load<T>(string key, string fileName)
 {
     string path = Application.persistentDataPath + "/" + fileName + "/";

     BinaryFormatter formatter = new BinaryFormatter();
     FileStream stream = new FileStream(path + key + fileType, FileMode.Open);

     T data = (T)formatter.Deserialize(stream);
     stream.Close();

     return data;
 }

 public static bool checkFile(string key, string fileName)
 {
     return File.Exists(Application.persistentDataPath + "/" + fileName + "/" + key + ".jesus");
 }

 public static bool checkDirectory(string fileName)
 {
     return Directory.Exists(Application.persistentDataPath + "/" + fileName + "/");
 }

 public static void deleteAll(string fileName)
 {
     string path = Application.persistentDataPath + "/" + fileName + "/";
     DirectoryInfo directory = new DirectoryInfo(path);
     directory.Delete(true);
     Directory.CreateDirectory(path);
 }

}

Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Bunny83 · Oct 11, 2020 at 01:58 AM

Windows is using backslashes \` while unix / mac / linux uses forward slashes /`. It' generally recommended to not use slashes at all but to use System.IO.Path.Combine instead.

 string path = System.IO.Path.Combine(Application.persistentDataPath, fileName);
 string file = System.IO.Path.Combine(path, key + fileType);


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

Answer by ThisLove · Oct 16, 2020 at 04:47 PM

@Bunny83 Thank you, that makes a lot of sense. When trying to create something to fix this: public static string convertPath(string fileName) { string path = Application.persistentDataPath; path = System.IO.Path.Combine(path, fileName); UnityEngine.Debug.Log(path); return path; }

 public static string convertPath(string[] fileNames)
 {
     string path = Application.persistentDataPath;// + "/" + fileName;// + "/";
     for (int i = 0; i < fileNames.Length; i++)
     {
         path = System.IO.Path.Combine(path, fileNames[i]);
     }
     UnityEngine.Debug.Log(path);
     return path;
 }

I added debugs to get e result and got this: "C:/Users/nopassword/AppData/LocalLow/DefaultCompany/Tiddle\Saves\Main/0:0" and "C:/Users/nopassword/AppData/LocalLow/DefaultCompany/Tiddle\Saves" along with the same error. I tried just correcting the problem by just adding my own slashes and had no suches.

Edit:I forgot to mention. This function is to get the file directory. I realize the names are confusing, I was just trying to make something that worked

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

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

The Semaphore Timeout Period Has Expired 0 Answers

CreateInstanceFromType is not allowed to be called during serialization 1 Answer

Error: GetComponentFastPath is not allowed? 2 Answers

UnityScript How To Deserialize? 1 Answer

I am getting a random serialization error and don't know why. How do I fix this? What is it saying? 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