How to merge files

Follow

Comments

2 comments

  • Avatar
    Benson_968 (Edited )

    Why not just use the Stream.CopyTo(Stream destination) method?

    FaceTime

    private static void CombineMultipleFilesIntoSingleFile(string inputDirectoryPath, string inputFileNamePattern, string outputFilePath)
    {
        string[] inputFilePaths = Directory.GetFiles(inputDirectoryPath, inputFileNamePattern);
        Console.WriteLine("Number of files: {0}.", inputFilePaths.Length);
        using (var outputStream = File.Create(outputFilePath))
        {
            foreach (var inputFilePath in inputFilePaths)
            {
                using (var inputStream = File.OpenRead(inputFilePath))
                {
                    // Buffer size can be passed as the second argument.
                    inputStream.CopyTo(outputStream);
                }
                Console.WriteLine("The file {0} has been processed.", inputFilePath);
            }
        }
    }
    1
    Comment actions Permalink
  • Avatar
    rory586

    This article is really amazing i hope we will see again this type of article in future. This information is really helpful for Kynect who really needs this. I hope you will many more write post like this. That's great. I was impressed by your writing. I am happy to see such a topic. Please come to my blog and read it.

    0
    Comment actions Permalink

Please sign in to leave a comment.