Hey Great community of Unity Answers. When a new user account (“Actually work order”) is created, it creates a directory for that given user. Then I want it to create a Text File in that directory with all the given information.
The Directory gets created just fine. With the help of Unity Answers, I was able to create and write to a Text File. However, I cant figure out, how to point the text file in the directory it just created. It just overwrites the same file over and over again. I tried an If statement but I am not a good programmer. This is my first real project. More of a learning experience than anything else. Here is my code so far for a work order. The code in question is at the bottom.
var workorderidGUI = "001";
var firstnameGUI = "First Name";
var lastnameGUI = "Last Name";
var custHomeNBRGUI = "000-000-0000";
var custCellNBRGUI = "000-000-0000";
var custStreetGUI = "";
var custCityGUI = "";
var custSTGUI = "";
var custZIPGUI = "";
var compDiag = "Enter Described Problem or Initial Troubleshooting.";
function OnGUI () {
workorderidGUI = GUI.TextField (Rect (885, 80, 40 , 20), workorderidGUI);
firstnameGUI = GUI.TextField (Rect (125, 80, 120, 20), firstnameGUI);
lastnameGUI = GUI.TextField (Rect (265, 80, 120, 20), lastnameGUI);
custHomeNBRGUI = GUI.TextField (Rect (135, 130, 100, 20), custHomeNBRGUI);
custCellNBRGUI = GUI.TextField (Rect (135, 160, 100, 20), custCellNBRGUI);
custStreetGUI = GUI.TextField (Rect (440, 130, 300, 20), custStreetGUI);
custCityGUI = GUI.TextField (Rect (440, 160, 100, 20), custCityGUI);
custSTGUI = GUI.TextField (Rect (580, 160, 30, 20), custSTGUI);
custZIPGUI = GUI.TextField (Rect (680, 160, 60, 20), custZIPGUI);
compDiag = GUI.TextField (Rect (60, 250, 360, 300), compDiag);
if (GUI.Button (Rect (25, 650, 120, 30), "Save Work Order")) {
//create Username
usernameGUI = firstnameGUI.Substring(0,1) + lastnameGUI.Substring(0,1) + workorderidGUI.Substring(0,1) + custHomeNBRGUI.Substring(0,1) + custCellNBRGUI.Substring(0,1) + custStreetGUI.Substring(0,1) + custCityGUI.Substring(0,1) + custSTGUI.Substring(0,1) + custZIPGUI.Substring(0,1);
//create Folder
if (!Directory.Exists ("C:/Data/" + firstnameGUI)) {
Directory.CreateDirectory ("C:/Data/" + firstnameGUI);
}
//Create Text file.
//save to textfile
System.IO.File.WriteAllText("C:/Data/data.txt", lastnameGUI + ", " + firstnameGUI + "," + workorderidGUI + "," + custHomeNBRGUI + "," + custCellNBRGUI + "," + custStreetGUI + "," + custCityGUI + "," + custSTGUI + "," + custZIPGUI);
}
}