DJ메탈짱™의 Free Style

[ASP.NET] 파일생성(StreamWriter), 폴더생성(CreateDirectory) 본문

일(job)/MS(Microsoft)

[ASP.NET] 파일생성(StreamWriter), 폴더생성(CreateDirectory)

뽀&쏭 2015. 12. 15. 13:13



// 폴더생성

private void button1_Click(object sender, EventArgs e)

{

string folderUrl = this.textBox1.Text;

string folderNm = "test";

for (inti = 1; i < 1000; i++)

{

Directory.CreateDirectory(folderUrl + "\\"+ folderNm + "_" + i.ToString());

}

this.label3.Text = "Directory Create OK";

}

// 파일생성

private void button2_Click(object sender, EventArgs e)

{

string folderUrl = this.textBox1.Text;

string folderNm = "test";

string dir = folderUrl + "\\" + folderNm; //저장될 디렉토리와 파일명

for (inti = 1; i < 1000; i++)

{

string filename = dir+"_"+i.ToString();

//this.label5.Text = filename + \\text.txt; 

FileStream fo = new FileStream(filename + "\\text" + "_" + i.ToString() + ".txt", FileMode.Create); 

StreamWriter so = new StreamWriter(fo, System.Text.Encoding.Default);

so.Write(this.textBox1.Text);

so.Close();

}

 this.label3.Text = "File Create OK"; 

}