Can someone explain to me how FileUtil.CopyFileOrDirectory works ?
While making my game I decided that I need to copy some files directly to a savefile for more clarity. But after finding this function on the Unity API I wasn't satisfied, its just too confusing to me and I cant find any useful information on it. Code isnt complicated but still confusing.
string savepath = @"Assets\Maps";
void Start()
{
Debug.Log(FileName(@"Assets\Scripts\testmap2.txt"));
//FileName() returns a string of the filename
Newmap(@"Assets\Scripts\testmap2.txt");
}
void Newmap(string path)
{
AssetDatabase.CreateFolder(savepath, FileName(path));
//this creates a folder i intend to store all data about the savefile in
FileUtil.CopyFileOrDirectory(path, savepath + '\\' + FileName(path));
//this is the topic of my question
//...
So what happens in this version of my code is that a folder is created but an error occurs afterwards : IOException: Failed to Copy File / Directory from 'Assets\Scripts\testmap2.txt' to 'Assets\Maps\testmap2': destination path already exists. I suspect that it might have something to do with names of the file and the folder. But it does not solve the issue when names are changed. Another thing I noticed is that when I remove everything after savepath in FileUtil.CopyFileOrDirectory, the file does not appear until I delete the other folder that was created there, even if its name is different. This is super weird and API added more confusion for me with the information that "All file separators should be forward ones "/"." which i do not understand why it would be that way my next guess would be to create a function that swaps all \ in a string to / but I wanted to make this post first.