2011-11-03 31 views
1

我正在寫一個錯誤日誌到文件在腳本存在的同一目錄。編號喜歡創建一個新的文件夾,因爲它會寫入文件名,並將日期/時間添加到文件名中,所以他們第二次不會保存在第一個文件夾中。我可以添加日期/時間輸出文件名在C#file.writeallbytes

這是我到目前爲止有:

File.WriteAllBytes( 「ERRORLOG.TXT」)

謝謝!

+0

這是一個有點陌生,寫入所有_Bytes_到* .txt文件 –

回答

4

你可以在它創建的DateTime有效的Windows文件名是這樣的:

string filename = "ErrorLogFolder" + DateTime.Now.ToString("dd-MM-yyyy_hh-mm-ss") + ".txt"; 
1

看看這個sample code命名文件

using System; 
using System.IO; 

class Program 
{ 
    static void Main() 
    { 
    // 
    // Write file containing the date with BIN extension 
    // 
    string n = string.Format("text-{0:yyyy-MM-dd_hh-mm-ss-tt}.bin", 
     DateTime.Now); 
    File.WriteAllText(n, "aaa"); 
    } 
} 
相關問題