Using Directory.Move to rename a folder is leaving the old folder behind and unable to be found to be deleted(UNITY)

Viewed 20

So i have a folder I'm trying to rename (I read i should use Directory.move to do this).

"ExampleA"

I use Directory.Move("ExampleA","New Folder") (code below)

Where "New Folder" is what "ExampleA" Should be renamed to, this works, it moves the directory and it's contents but it's also leaving the "ExampleA" folder still there, and when i try and delete it it says It Doesn't exist.

Full Code here

string oldDirectory = Application.dataPath + "/Photos/" + GameObject.Find("Camera").GetComponent<CameraController>().cardNames[assignmentButton];
    Directory.Move(oldDirectory, Application.dataPath + "/Photos/" + renameInput.text);
    Debug.Log("Attempting to delete: " + oldDirectory);
    if(Directory.Exists(oldDirectory))
        Directory.Delete(oldDirectory,true);

The old directory does indeed exist, but this code seems to think it doesn't, i get thrown an error saying it doesn't exist if i remove the Directory.Exists check.

1 Answers

It doesn't appear to happen in a built unity project, it works completely as intended. My guess is that there's an issue with File.
Delete working in the unity directory or that my unity directory is currently in a Github folder which may limit my use of deleting files. So because of this, I'll class this as answered.

Related