How to disable a scene in a build settings from code ?

I need to create an editor script that I can use to disable a given set of scenes in the build settings.
I have this code, but it doesn’t work. I would highly appreciate if you could help me with this.
Thanks

private bool level1 = true;
void OnGUI ()
{
level1 = EditorGUILayout.Toggle("Level 1", level1);
		if (level1)
		{
			
			EditorBuildSettingsScene[] arr = EditorBuildSettings.scenes.Where(s => s.path.Equals("Assets/_Scenes/Games/level1.unity")).ToArray();
			arr[0].enabled = true;
		}
}

Could do something like this:

	private bool level1 = true;
	void OnGUI ()
	{
		level1 = EditorGUILayout.Toggle("Level 1", level1);
		SetScene("level 1", level1);
	}

	void SetScene(string sceneName, bool sceneEnabled)
	{
		EditorBuildSettingsScene[] scenes = EditorBuildSettings.scenes;
		foreach(EditorBuildSettingsScene scene in scenes) 
		{
			if (scene.path.Contains(sceneName))
			{
				scene.enabled = sceneEnabled;
			}
		}
		EditorBuildSettings.scenes = scenes;
	}

For more info, read this: Unity Answer: How do I set the EditorBuildSettingsScene.enabled property?