- Home /
Modifying a text file outside unity.
Hey, so I've got some code that creates a text file with some player data in it, but I can't figure out how to either:
a)modify a value in the text file, or alternatively b)delete the text file so I can rewrite it with new values.
Here's the function I'm attempting to write:
function updatePlayerData()
{
Delete(docPath); //this line throws an error.
var sr = File.CreateText(docPath);
for(var i=0; i< playerInfoRealArray.length; i++)
{
sr.WriteLine (playerInfoRealArray[i]);
}
Debug.Log("Updated the player's data.");
sr.Close();
}
Any idea how to do it?
Thanks!
Comment
Best Answer
Answer by DaveA · Nov 04, 2011 at 02:53 PM
http://msdn.microsoft.com/en-us/library/system.io.file.aspx
Check that the file exists with File.Exists and delete with File.Delete. To modify, you have to read the file (into strings if that's what you're doing), modify them, then write it out.
Thanks! You're a pal. I'll just delete the crap out of the file, as it's more relaxing to start afresh.