static void Main(string[] args)
{
var sourceDirectory = @"C:\target\new\";
var txtFiles = Directory.EnumerateFiles(sourceDirectory, "*.txt");
foreach (string currentFile in txtFiles)
{
StreamReader exportedfiles = new StreamReader(currentFile, System.Text.Encoding.Default);
using (FileStream readStream = File.OpenRead(currentFile))
//Specify path for the combined file that will be created.
using (FileStream writeStream = File.OpenWrite("C:\\file.txt"))
{
BinaryReader reader = new BinaryReader(readStream);
BinaryWriter writer = new BinaryWriter(writeStream);
byte[] buffer = new byte[10240]; //Equals a 10mb buffer.
int bytesRead;
while ((bytesRead = readStream.Read(buffer, 0, 10240)) > 0)
{
writeStream.Write(buffer, 0, bytesRead);
}
}
}
Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.
”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.
Our community of experts have been thoroughly vetted for their expertise and industry experience.
The Distinguished Expert awards are presented to the top veteran and rookie experts to earn the most points in the top 50 topics.