"Access to path (path) is denied."

Hello, I’m trying to have Unity, through script, create a file (or overwrite one that is already there) in the “Application.persistentDataPath”.
When I try to delete or overwrite a file, I get

"UnauthorizedAccessException: Access to path 'C:\Users\[user]\AppData\LocalLow\DefaultCompany\[project]\Temp\' is denied"

In case you’re wondering what I’m doing in code:

       string appDataFilePath = Application.persistentDataPath + "/Temp/";
        if (!Directory.Exists(appDataFilePath))
        UnityEditor.FileUtil.DeleteFileOrDirectory(appDataFilePath + "test.png");

I’ve gone to a lot of different questions and no one seems to be doing this much, but I still want to try to get this working, and I can’t get why access to this is denied. I don’t want to have to use admin privileges to be able to do it.
Maybe I’m doing this whole thing wrong and if there’s an easier way to do this, I’d love to try that too. Basically I’m trying to read the bytes from a PNG file and change and read them, and then save the edited png again in the appdata folder for later use.

Hi @noahgrosh,
The problem here is that your user does not have permissions to Write/Read over the “Temp” Folder.

Maybe you can try to save the files in the persistentDataPath, (Without creating the Temp folder) Or check in the code if the directory has Read/Write permissions to handle the error. Otherwise you can’t do much without having permissions. :confused:

Aha, apparently my entire LocalLow folder is read-only. I don’t know if that’s normal or not, but as soon as I set my DefaultCompany folder to not be read-only it works.
For anyone who has this same issue, that’s probably what would work for you. If this is a normal thing for everyone’s computer that LocalLow is read-only, I might need to save to another location.