Deleting a file inside a BeginArea and BeginHorizontal

Right now I’m trying to delete a save file.

My save files are loaded within a foreach loop and hooked to buttons. Tapping the button loads the corresponding level.

I realized I had no way to delete these levels, and so I tried to implement what I thought would be pretty easy.

void OnGUI()
{
	GUILayout.BeginArea(new Rect(Screen.width*.545f,(Screen.height*.25f+scrollPosition.y*-1),Screen.width*.45f,Screen.height*.7f));

	GUILayout.Label("Saved maps");
	foreach (var f in dir.GetFiles("*.dm"))
	{	
		string del = ",";
		string text = System.IO.File.ReadAllText(f.FullName);
		string[] lines = Regex.Split(text, "

");
string cells = Regex.Split(lines[lines.Length-2], del);

		GUILayout.BeginHorizontal();
		if(GUILayout.Button (cells[1]+":"+cells[0]+"  "+cells[4], GUILayout.Width(Screen.width*.349f), GUILayout.Height(Screen.height*.06f)))
		{
			StartCoroutine("LoadOld");
			//Application.LoadLevel("Table");
		}
		if(GUILayout.Button ("Del", GUILayout.Width (Screen.width*.349f), GUILayout.Height(Screen.height*.06f)));
		{
			File.Delete(f.FullName);
		}

		GUILayout.EndHorizontal();
	}

	GUILayout.EndArea();
}

The problem occurs when I add the second button (including both buttons in a Horizontal layout) and suddenly when ever the scene loads it deletes all the files without any user input. What’s going wrong here?

You have a “;” after your if(GUILayout.Button ("Del", GUILayout.Width (Screen.width*.349f), GUILayout.Height(Screen.height*.06f)));, which means { File.Delete(f.FullName); } always executes.