How can I write a variable value to txt file, and also give it the same name of another variable?

I am trying to use javascript and unity to transfer words from one txt file and into another.

I have this code so far. Unity doesn’t show any errors, but nothing is written to the txt file. What am I doing wrong?

    import System.IO;
    //var fileName = "C:/unity/writetest.txt";
    var fileName = "writetest.txt";
    var number1 : String;
    var wordname : String;    
    function Start () {
    var wordname : String = "aardvark";
    var sr = new StreamReader(Application.dataPath + "/" + fileName);
    var fileContents = sr.ReadToEnd();
    var lines = fileContents.Split("

number1 = lines[2];

    function Update() {

    //check number of second line
    if (number1 == "1"){

       System.IO.File.WriteAllText("C:/unity/data.txt", wordname );
       //create txt file with value of 'wordname'
    if (number1 == "0"){


I would also like the txt file to be named the same as the value of another variable. How would I go about this?

In other words, the first line in a txt file is Bob, so the script then creates a txt file called bob, then writes a word to it.

Try with

 System.IO.File.WriteAllText(@"C:\unity\data.txt", wordname );

See the @ on the front.

Also you want to check if the directory exists:

if (!Directory.Exists(@"C:\unity\")){