How to create a directory using Directory in C#?

Use the Directory.CreateDirectory method in C# to create directories. Here is an example code:

using System;
using System.IO;

class Program
{
    static void Main()
    {
        string directoryPath = @"C:\Temp\NewDirectory";

        // 创建目录
        Directory.CreateDirectory(directoryPath);

        Console.WriteLine("目录已创建:{0}", directoryPath);
    }
}

After running the above code, a new directory named NewDirectory will be created in the C:\Temp directory.

Leave a Reply 0

Your email address will not be published. Required fields are marked *


广告
Closing in 10 seconds
bannerAds