判斷C:\Test 是否存在

若不存在則透過 System.IO.Directory.CreateDirectory(dirPath); 來建立資料夾

 

string dirPath = @"C:\Test";

if (Directory.Exists(dirPath))
{
    Console.WriteLine("此資料夾 {0} 已存在。", dirPath);
}
else
{
    System.IO.Directory.CreateDirectory(dirPath);
    Console.WriteLine("此資料夾 {0} 已建立。", dirPath);
}


arrow
arrow

    Roger 發表在 痞客邦 留言(0) 人氣()