如果dirPath中有不存在的資料夾,CreateDirectory會順便建立此資料夾。
下列範例會在C:\底下建立一個TestDir
using System; using System.IO; public class Program { public static void Main() { string dirPath = @"C:\TestDir"; if (Directory.Exists(dirPath)) { Console.WriteLine("The directory {0} already exists.", dirPath); } else { Directory.CreateDirectory(dirPath); Console.WriteLine("The directory {0} was created.", dirPath); } } }
沒有留言:
張貼留言