I'm confusing myself editing this c# script for Unity, please correct any weirdness with the filenames and make it clearer when it comes to whats a folder path and whats a filename in the function

using UnityEngine;
using System.Collections;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using System;
using System.IO;

public class ExportRuntimeExample : MonoBehaviour
{
	public GameObject Sim;
	private List<GameObject> SimObjects = new List<GameObject>();
	public string ExportFolderPath = string.Empty;
	public UnityEngine.UI.Slider progressBar; // Reference to the UI Slider for progress

	public static string SanitizeFilename(string filename)
	{
		// Define a regex pattern for invalid characters
		string invalidCharsPattern = @"[\\/:*?""<>|]";
		filename = Regex.Replace(filename, invalidCharsPattern, string.Empty);
		return filename.Trim();
	}

	void GetSimChildren()
	{
		Sim = FindSim();
		SimObjects.Clear();

		// Add all children to SimObjects
		foreach (Transform child in Sim.transform)
		{
			SimObjects.Add(child.gameObject);
		}
	}

	public GameObject FindSim()
	{
		return GameObject.FindGameObjectWithTag("TerrainOBJ");
	}

	public void ExportSimBatch()
	{
		// Start the coroutine to export with progress
		StartCoroutine(ExportWithProgress());
	}

	private IEnumerator ExportWithProgress()
	{
		GetSimChildren();

		if (SimObjects == null || SimObjects.Count == 0)
		{
			Debug.LogWarning("No simulation objects found for export.");
			yield break;
		}

		int totalObjects = SimObjects.Count;

		for (int i = 0; i < totalObjects; i++)
		{
			GameObject mesh = SimObjects[i];
			string sanitizedFilename;

			if (!string.IsNullOrEmpty(mesh.name))
			{
				sanitizedFilename = SanitizeFilename(mesh.name);
			}
			else
			{
				// Generate a unique filename if the mesh name is empty
				sanitizedFilename = "UnnamedMesh_" + Guid.NewGuid().ToString(); // Or use a timestamp
			}

			try
			{
				ExportRuntime(mesh, sanitizedFilename);
			}
			catch (Exception ex)
			{
				Debug.LogError($"Failed to export {mesh.name}: {ex.Message}");
			}

			// Update the progress bar
			progressBar.value = (float)(i + 1) / totalObjects;
			yield return null; // Wait until the next frame to avoid blocking
		}

		Debug.Log("Export complete.");
	}

	public void ExportRuntime(GameObject Gameobject, string FolderName)
	{
		ExporterRuntime ex = this.gameObject.GetComponent<ExporterRuntime>();
		if (ex != null)
		{
			string FilePath = @ExportFolderPath + @"\" + SanitizeFilename(GameObject.FindGameObjectWithTag("TerrainOBJ").name);
			Directory.CreateDirectory(FilePath);

			ex.ExportObj(Gameobject, @ExportFolderPath + @"\" + SanitizeFilename(GameObject.FindGameObjectWithTag("TerrainOBJ").name), FilePath);
		}
		else
		{
			Debug.LogError("ExporterRuntime component not found on the GameObject.");
		}
	}
}


'more insight into scripts outside of this one below'
	public static async Task ExportGOToOBJAsync(Transform[] selection, string mainPath, string filename)
	{
		mainPath = Path.Combine(mainPath, filename);
		Directory.CreateDirectory(mainPath);

		List<MeshFilter> mfList = new List<MeshFilter>();
		foreach (var trans in selection)
		{
			var meshFilters = trans.GetComponentsInChildren<MeshFilter>();
			mfList.AddRange(meshFilters);
		}

		if (mfList.Count > 0)
		{
			MeshFilter[] mf = mfList.ToArray();
			// Check if the filename is empty and generate a unique one if true
			if (string.IsNullOrEmpty(filename))
			{
				// Generate a unique filename using the current timestamp
				filename = "ExportedMesh_" + DateTime.Now.ToString("yyyyMMddHHmmss");
			}

			await MeshesToFileAsync(mf, mainPath, filename);
			Debug.Log($"Exported: {mainPath}/{filename}");
		}
		else
		{
			Debug.LogWarning("Error exporting. Make sure you selected the object.");
		}
	}
}