Checks if the specified directory exists and create it if not present. - CSharp File IO

CSharp examples for File IO:Directory

Description

Checks if the specified directory exists and create it if not present.

Demo Code


using System.IO;//from   w  w w .j  a va  2 s. co  m

public class Main{
        /// <summary>
        /// Checks if the specified directory exists and create it if not present.
        /// </summary>
        /// <param name="directoryName">Name of the directory.</param>
        public static void CheckIfExistsAndCreate(string directoryName)
        {
            if (!Directory.Exists(directoryName))
            {
                Directory.CreateDirectory(directoryName);
            }
        }
}

Related Tutorials