In Unity3D, How would I use something like this: path = "C:\Users\Jonathan\Documents\FileData" + fileName + ".txt";
so I can make a for loop and create several text files under desired path?
The loop looks like this currently:
named = namesAsset.text.Split ('\n');
sliced = statAsset.text.Split ('\n');
for (int i = 0; i < named.Length; i++) {
fileName = named[i].ToLower();
path = "C:\Users\Jonathan\Documents\FileData" + fileName.Substring(1) + ".txt";
File.WriteAllText(path, sliced[i]);
Debug.Log (named[i]+".txt");
}
But there is a problem: They won't accept this! It spits out the error that the name has an invalid char.
Full script:
using UnityEngine;
using UnityEditor;
using System.IO;
using System.Text;
using System;
public class SplitPage : ScriptableWizard {
public TextAsset statAsset;
public TextAsset names;
public string[] named = new string[151];
public string[] sliced = new string[151];
public string path;
public string fileName;
[MenuItem("GameObject/SlicePage")]
static void CreateWizard() {
ScriptableWizard.DisplayWizard<SplitPage>("Split Text File", "Create");
}
void OnWizardCreate() {
named = names.text.Split ('\n');
sliced = statAsset.text.Split ('\n');
for (int i = 0; i < named.Length; i++) {
fileName = named[i].ToLower();
path = "C:\Users\Jonathan\Documents\FileData" + fileName.Substring(1) + ".txt";
File.WriteAllText(path, sliced[i]);
Debug.Log (named[i]+".txt");
}
}
}