• Notice regarding image hosts and attachments. See here.

c# help

Associate
Joined
30 Sep 2004
Posts
1,038
Location
Colchester, Essex
I have a list of filenames in a variable (seperated by newlines) and I want to merge them all into one file with a specified file name. How would I do that? (by merge, I mean copy the first one to newfilename and then append the second and third and so on)
 
I managed to make it work with the following nifty bit of code:
Code:
foreach (string fileWithR in fileNames)
{
	if (fileWithR.Length != 0)
	{
		string file = fileWithR.Substring(0, fileWithR.Length - 1);
		using (FileStream readfs = File.OpenRead(file)) using (FileStream writefs = new FileStream(outputFileNames[z], FileMode.Append, FileAccess.Write))
		{
			int b; byte[] buffer = new byte[10240];
			while ((b = readfs.Read(buffer, 0, 10240)) > 0) writefs.Write(buffer, 0, b);
		}
	}
}
 
Back
Top Bottom