- Home /
creating files in path and load it problem;
i am trying to create saved files in A specific path and load them using Directory class the problem is when i create the save file it goes to the project folder instead of the created folder how do i fix it`
int score = 10;
string playername = "player1";
public InputField savename;
const string foldername = "Save";
const string fileextnison = ".txt";
string filesavename;
string folderPath = Path.Combine(Application.persistentDataPath, foldername);
public void savedfiles()
{
filesavename = savename.text;
BinaryFormatter bf = new BinaryFormatter();
FileStream file = File.Create(folderPath + filesavename + fileextnison);
PData playerdata = new PData();
playerdata.scorer = this.score;
playerdata.names = this.playername;
bf.Serialize(file, playerdata);
file.Close();
}`
hello override this line and tell me if it works :)
FileStream file = File.Create(Application.persistentDataPath + "/" + filesavename + fileextnison);
it's work thank youuuuuuuuu but could you explain it pllls thank you again
pretty sure you were only missing a "/" before the filesavename since without it it will think the folder name is all foldername and filename, i will change it to an answer so you can mark it as correct :)
Answer by xxmariofer · Mar 04, 2019 at 09:19 AM
sorry missed one part
FileStream file = File.Create(Application.persistentDataPath + "/" + foldername + "/" + filesavename + fileextnison);
Answer by misher · Mar 04, 2019 at 09:10 AM
First, you need to create a directory:
If(!Directory.Exists([folder path])) { Directory.Create([folder path]); }
then create a filename: filesavename + fileextnison;
then use Path.Combine() to fomr the full path of your file:
Path.Combine([folder path], [filepath]);
i create directory in the start function problem solved thank you.