後來才知道,不存在的路徑+檔案,是無法一次建立的。(目前所知)

 

建立「資料夾」的方法(含一連串不存在的目錄):

using System.IO;
// ...
if ( ! Directory.Exists(@"C:\temp\Test\text") )
    Directory.Create(@"C:\temp\Test\text");

 

建立「檔案」的方法:

using System.IO;
// ...
if ( ! File.Exists(@"C:\temp\Test\text\test.txt") )
    File.Create(@"C:\temp\Test\text\test.txt");

 

參考:
C# Basic - Creating a File and Directory
How do I create a file AND any folders, if the folders don't exist?
 

 

arrow
arrow

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