Here is the scenario:
I have a directory with 2 million files. The code that I have below writes all the files in about 90 minutes. Does anyone have a way to speed it up or make this code more efficient? I would also like to just write the file names in a list.
string lines = (listBox1.Items.ToString()); string sourcefolder1 = textBox1.Text; string destinationfolder = (@"C:\anfiles"); using (StreamWriter output = new StreamWriter(destinationfolder + "\\" + "MasterANN.txt")) { string[] files = Directory.GetFiles(textBox1.Text, "*.txt"); foreach (string file in files) { FileInfo file_info = new FileInfo(file); output.WriteLine(file_info.Name); } }
Slowdown is that it writes out 1 line at a time.
It takes about 13-15 minutes to get all the files that need to be written.
The next 75 minutes create the file.
c # file-io
user222427
source share