I am trying to concatenate some file name constituents to make sure if I already have an identically-named file, the new one gets a new name with an underscore and an incremental counter.
I have written the following which I believe should work:
string tempPath = Path.Combine(Application.dataPath, "MyValues");
tempPath = Path.Combine(tempPath, "_");
tempPath = Path.Combine(tempPath, counter.ToString() + ".csv");
After I noticed no file is actually saved, I included Debug.Log(tempPath)
to see what it returns, and surprisingly I get the following:
MyUnityProject/Assets\MyValues\_\0.csv
Firstly, why are there \
instead of /
?
Also, where are the backslashes surrounding the underscore coming from?
Finally, instead of manually removing them, how could I get the correct syntax back? For example MyValues_0.csv
, MyValues_1.csv
, etc...