我想生成幾個文件,所以我寫了這個代碼,其中value
得到但我只得到一個文件創建,爲什麼?應該不是797文件呢?什麼是錯在我的代碼?:生成很多文件不起作用
private void button3_Click(object sender, EventArgs e)
{
int value = bdCleanList.Count()/Int32.Parse(textBox7.Text);
MessageBox.Show(value.ToString());
string bases_generadas =
System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory,
"bases_generadas");
for (int i = 1; i < value; i++)
{
string newFileName = "bases_generadas_" +
DateTime.Now.ToString("dd-MM-yyyy-hh-mm-ss") +
".txt";
using (System.IO.FileStream fs =
System.IO.File.Create(
System.IO.Path.Combine(bases_generadas, newFileName)))
{
for (byte j = 0; j < 10; j++)
{
fs.WriteByte(j);
}
}
}
}
編輯爲@安德烈 - shchekin建議我增加了一個i
到newFileName
所以現在的代碼,這是一個:
string newFileName = "bases_generadas_" + i +
DateTime.Now.ToString("dd-MM-yyyy-hh-mm-ss") + ".txt";
但現在我運行代碼一次value
需要只是3個文件的創建:
bases_generadas_124-04-2013-11-45-08.txt
bases_generadas_224-04-2013-11-45-08.txt
bases_generadas_324-04-2013-11-45-08.txt
爲什麼?
您是否嘗試過調試? 「價值」是797嗎? 'newFileName'每次迭代都會得到新名字? – Guy 2013-04-25 04:15:41
@Guy看到我的編輯 – Reynier 2013-04-25 04:17:15
這是因爲你從'1'運行到'<4' – Guy 2013-04-25 04:17:48