C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
Further: Your installation or upgrade process might have mistakenly removed it, for reasons beyond your control.
However: We can try to ensure a path exists, and create it if it doesn't, with a method similar to this one.
C# program that ensures path exists
using System;
using System.IO;
class Program
{
public static void EnsurePathExists(string path)
{
// ... Set to folder path we must ensure exists.
try
{
// ... If the directory doesn't exist, create it.
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
}
catch (Exception)
{
// Fail silently.
}
}
static void Main()
{
// Test the method.
EnsurePathExists(@"C:\programs\exampledir\");
Console.WriteLine("DONE");
}
}
Output
DONE
Also: The code catches it own exceptions when it cannot do its job. We should use exceptions when code cannot do what it needs to do.
ExceptionDirectory: This is a static class in the IO namespace. You can call Exists and CreateDirectory on it.
DirectoryNote: Thanks to Nikolai Wanner for showing that CreateDirectory can be used without an initial Directory.Exists check.