If a folder does not exist, create it

As others have said, use System.IO.Directory.CreateDirectory.

But, you don’t need to check if it exists first. From the documentation:

Any and all directories specified in path are created, unless they already exist or unless some part of path is invalid. If the directory already exists, this method does not create a new directory, but it returns a DirectoryInfo object for the existing directory.

Leave a Comment