パスへのアクセスは拒否されました Access to the path is denied.

ネットで拾ったスクリプトでフォルダを作るのとそこにファイルを作って入れようとしたのですが…
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.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;
using System;

public class スクリプト編集 : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
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
void Update()
{
    
}

}
<備考 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”;
    if (!System.IO.Directory.Exists(folderPath))
    {
    System.IO.Directory.CreateDirectory(folderPath);
    }

  • 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.