ใช้ Directory.CreateDirectory(path) สร้างโฟลเดอร์ (รวมโฟลเดอร์แม่ที่ยังไม่มี) คืนค่า DirectoryInfo ของโฟลเดอร์ที่สร้าง
ตัวอย่างโค้ด
using System;
using System.IO;
public class Program
{
public static void Main()
{
Directory.CreateDirectory(@"D:\Tutorial");
Console.WriteLine("Directory created (if not exists).");
}
}
พฤติกรรม: หากโฟลเดอร์มีอยู่แล้ว ไม่ Error และไม่ทำอะไร (Idempotent) สร้างโฟลเดอร์แม่อัตโนมัติ