how to Export unity data in different path everytime?

Hi

I have a C# scripts that I am using it to export some of the data from Unity.
Because I need to run this simulation multiple times I did “Build” and now I am running .exe file with batFile multiple times. Currently, the exported file will be saved in AppData. The problem is that I need to seperate each runs output in different folder in AppData to be understanble which file belongs to with run.
Does anybody have any idea about it?
To be more clear, in one run, project.exe generates like 10 .xml file, if I run it 100 times, I will have 1000 .xml files that I can’t seperate with date or anything else as this is quite short simulation runs for few seconds only.

It depends on your exact needs. There are several solutions though I just mentioned two here.

  • First you could simply create a new folder which you could simply name after a random GUID when the application got started and place whatever files you generate in that subfolder. Of course if you don’t want to use subfolders you could use that GUID as a prefix for your file names.
  • If you need more control over where the data is placed, you could simply pass a path / prefix as an argument to your application. You can access the commandline arguments with System.Environment.GetCommandLineArgs(). Since you start your application from a batch file, you probably use a for loop where you have a loop count which you can simply use in your naming scheme, maybe additionaly to the date/time.

Thank you for the response.
I didn’t quite understand the first solution’s second part!
currently my files name will be “log-” + basename + “.xml”, and you are suggesting add a GUID (as I searched I think this is kind of random string) as prefix to my fille name! If my understanding is correct, It won’t change anything as I will have thousands of file with random names as before.

For the second solution, in this case, do i need to insert file name everytime the .exe runs?

He’s suggesting you acquire a GUID and make 1 folder with that GUID as part of its name. All your outputs from that run go into the same folder. That way, each run’s results are completely and reliably separated from all other runs.

1 Like