UnauthorizedAccessException: Access to the path’C:\Users\User\Myproject\Assets\Scripts\File\SubFolder1’ is denied.（ガバ翻訳曰く“ UnauthorizedAccessExceptionです： パス 'C:¥UsersUser¥My project¥Assets¥Scripts¥File¥SubFolder1’へのアクセスは拒否されました。”という意味らしい）と表示されちゃいました。どうすればいいですか。お告げをください。
I used a script I found on the internet.I want to create a folder with this and put files in it as well.ButAn error occurred with the indication “UnauthorizedAccessException: Access to the path’C:\Users\User\Myproject\Assets\Scripts\File\SubFolder1’ is denied.”.what can I do?Please help.
（Sorry for my poor English.）
＜使ったスクリプト Scripts used＞
Pause immediately after the game starts.Pause button to resume.
public class スクリプト編集 : MonoBehaviour
// Start is called before the first frame update
string folderPath1 = Path.Combine(Application.dataPath, @“Scripts\File\SubFolder1”);
string filePath1 = Path.Combine(folderPath1, “data1.txt”);
FileStream fs1 = null; Directory.CreateDirectory(folderPath1); fs1 = File.Create(folderPath1);
// Update is called once per frame
＜備考 Additional Information＞
Please stop posting the same question so many times, I have already removed one of your posts from the forum. I will try to answer to the best of my knowledge based on the limited information in english:
The error you’re encountering is likely due to insufficient permissions to access or modify the specified directory. To resolve this issue, follow these steps:
Verify the folder path: Double-check the folder path in your script to ensure it’s pointing to the correct location within your Unity project.
Run Unity as Administrator: Close Unity, right-click on the Unity icon, and select “Run as administrator.” This will grant Unity the necessary permissions to access and modify files in protected folders.
Check folder permissions: Ensure that the folder you’re trying to access or modify has the correct permissions set. To do this, right-click on the folder, select “Properties,” then navigate to the “Security” tab. Ensure that the user running Unity has the necessary permissions (Read, Write, Modify) to work with the folder.
Ensure the folder exists: Make sure that the folder you’re trying to access or modify exists. If it doesn’t, create it manually or modify your script to create the folder before attempting to access or modify it. You can use the following C# code snippet to create a directory if it doesn’t already exist:
string folderPath = “C:\Users\User\Myproject\Assets\Scripts\File\SubFolder1”;
Check for file locks: Ensure that no other programs or processes are accessing or locking the files within the folder you’re trying to modify. Close any other instances of Unity or Visual Studio that might be using the same files.
If you’re still encountering issues after following these steps, please share the script you’re using to create the folder and put files in it. This will help identify if there are any issues with the script itself.