- Home /
Creating a save.xml file and a folder to stash it in
I have a test application that creates a save file which collects all the user info. Now, when I run the application as an executable it doesn't create its own save file where the executable is located. It still uses the same save.xml file located within unity's Asset folder. Is there a way for me to create a folder, call it "My Saves" and then create the save.xml save data there? Thank you in advanced!
if you can show us how you are saving and accessing the file, we can help you solve this.
void CreateX$$anonymous$$L()
{
StreamWriter writer;
FileInfo t = new FileInfo(Application.dataPath + "\\" + _FileName);
if(!t.Exists)
{
writer = t.CreateText();
}
else
{
t.Delete();
writer = t.CreateText();
}
writer.Write(_data);
writer.Close();
Debug.Log("File written.");
}
void LoadX$$anonymous$$L()
{
StreamReader r = File.OpenText(Application.dataPath + "\\"+ _FileName);
string _info = r.ReadToEnd();
r.Close();
_data=_info;
Debug.Log("File Read");
}
Answer by Sparrowfc · Dec 04, 2013 at 08:55 AM
How do you set the path of your save file? Seems like your target platform is Windows/Mac Standalone, then you can use Application.dataPath to locate your excutable file path, and set your path base on that
I am setting everything up like so: // Finally our save and load methods for the file itself
void CreateX$$anonymous$$L()
{
StreamWriter writer;
FileInfo t = new FileInfo(Application.dataPath + "\\" + _FileName);
if(!t.Exists)
{
writer = t.CreateText();
}
else
{
t.Delete();
writer = t.CreateText();
}
writer.Write(_data);
writer.Close();
Debug.Log("File written.");
}
void LoadX$$anonymous$$L()
{
StreamReader r = File.OpenText(Application.dataPath + "\\"+ _FileName);
string _info = r.ReadToEnd();
r.Close();
_data=_info;
Debug.Log("File Read");
}