I am relatively new to using files and creating directories in C#, but I have been stuck for a while. I receive the following error: System.UnauthorizedAccessException: 'Access to the path 'C:\Program Files\Skyroom' is denied.'
Here is my code in case it helps:
if (File.Exists(@"C:\Program Files\Skyroom\gamedata.txt")) { Console.WriteLine("Game loading. Please wait.."); Thread.Sleep(500); Console.Clear(); Console.WriteLine("Game loading. Please wait..."); Thread.Sleep(500); Console.Clear(); Console.WriteLine("Game loading. Please wait."); Thread.Sleep(500); Console.Clear(); Console.WriteLine("Game loading. Please wait.."); Thread.Sleep(500); Console.Clear(); Console.WriteLine("Game loading. Please wait..."); Thread.Sleep(500); Console.Clear(); } else { Directory.CreateDirectory(@"C:\Program Files\Skyroom"); File.Create(@"C:\Program Files\Skyroom\gamedata.txt"); Main(); } Thank you. Any info needed, just ask.