How to check if a folder exists and create it if not? C#
Hi everyone! I'm a beginner C# developer and I'm writing a small application for saving logs. I need the program to check if the Logs folder exists in the project root when it starts, and create it if it doesn't. I tried doing this:\n\n```csharp\nstring path = "Logs";\nif (!Directory.Exists(path))\n{\n Directory.CreateDirectory(path);\n}\n```\n\nBut I have a few questions. First, am I using Directory.Exists correctly? I've heard there might be permission issues. Second, if the folder already exists, will CreateDirectory throw an error? I've read that the CreateDirectory method can throw an exception if the path is invalid, but I'm not sure about an existing folder. Third, what about relative paths? My application runs from different locations, and I'm afraid
No answers yet.
Log in to leave an answer