473,473 Members | 2,122 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Concatenate numerous large binary or text files into one

Hi,
I would like to find out the fastest way to concatenate large (200 or
300MB) and numerous (500 - 700) files (Postscript files) into a single
one (which can ends up being several GigaB) using csharp within a
windows form application.
One of the requirement also is to make sure the output file is closed
only when the concatenation is done so that the next application using
the file (printer spool) does not assume it is finished unledd it is
actually finished.

Thanks in advance for your help.

Sep 30 '06 #1
2 13801
ff*****@gmail.com wrote:
I would like to find out the fastest way to concatenate large (200 or
300MB) and numerous (500 - 700) files (Postscript files) into a single
one (which can ends up being several GigaB) using csharp within a
windows form application.
One of the requirement also is to make sure the output file is closed
only when the concatenation is done so that the next application using
the file (printer spool) does not assume it is finished unledd it is
actually finished.
Efficient reading and writing of files should just be a
matter of using huge buffers.

I would be more worried about whether PDF files
can just be concatenated.

Arne
Sep 30 '06 #2


<ff*****@gmail.comwrote in message
news:11**********************@h48g2000cwc.googlegr oups.com...
Hi,
I would like to find out the fastest way to concatenate large (200 or
300MB) and numerous (500 - 700) files (Postscript files) into a single
one (which can ends up being several GigaB) using csharp within a
windows form application.
One of the requirement also is to make sure the output file is closed
only when the concatenation is done so that the next application using
the file (printer spool) does not assume it is finished unledd it is
actually finished.
Well, you don't really need the fastest way. You need a reasonably fast
way. Just use System.IO.FileStream, open one for your output file, and
iterate over your input files. For each input file, read a buffer from the
input file, write the buffer to the output file, repeat.

You don't need to use huge buffers, and it's probably not worth while to use
async IO or double buffering or any of that.

Here's a simple file concatenation program:

David

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace FileConcat
{
class Program
{
static int Main(string[] args)
{
if (args.Length != 2)
{
Console.WriteLine("usage FileConcat [SourceDir] [DestinationFile]");
}
try
{
Run(args[0],args[1]);
return 0;
}
catch (Exception ex)
{
Console.WriteLine(ex);
return 1;
}
}
static void Run(string SourceDir, string OutputFileName)
{
string[] inputFiles = Directory.GetFiles(SourceDir);

int bufSize = 1024 * 64;

byte[] buf = new byte[bufSize];

using (FileStream outFile =
new FileStream(OutputFileName, FileMode.OpenOrCreate,
FileAccess.Write, FileShare.None, bufSize))
{
foreach (string inputFile in inputFiles)
{
using (FileStream inFile =
new FileStream(inputFile, FileMode.Open, FileAccess.Read,
FileShare.Read, bufSize))
{
int br = 0;
while ((br = inFile.Read(buf,0,buf.Length))0)
{
outFile.Write(buf,0,br);
}
}
}
}

}
}
}
Sep 30 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: CSN | last post by:
Is it possible to iterate over an array in plpgsql? Something like: function insert_stuff (rel_ids int) .... foreach rel_ids as id insert into table (rel_id, val) values (id, 5);
13
by: jt | last post by:
I can't seem to find a way to concatenate strings that have nulls within the string. I have a string that I need another string that has nulls in it and what to append the 2nd string, 3 string...
14
by: J.S. | last post by:
In a Windows Form application, which is the better method to concatenate large blocks of code? 1. Reading the text from text files. 2. Adding the text to the VB file itself? Thanks! J.S. ...
2
by: gauravkhanna | last post by:
Hi All I need some help for the below problem: Scenario We need to send large binary files (audio file of about 10 MB or so) from the client machine (.Net Windows based application, located...
68
by: vim | last post by:
hello everybody Plz tell the differance between binary file and ascii file............... Thanks in advance vim
6
by: Sheldon | last post by:
Hi, I am trying to build a large array using concatenate function in python. So as I loop over the number of arrays, of which there are 12 (4 down and 3 across), I create 3 long arrays by...
20
by: mike | last post by:
I help manage a large web site, one that has over 600 html pages... It's a reference site for ham radio folks and as an example, one page indexes over 1.8 gb of on-line PDF documents. The site...
3
by: sebastian.harko | last post by:
Helllo, What's the general accepted strategy for dealing with very large binary files in C# ? I have to do a program that reads some "multi frame bitmap " files which can reach up to one...
1
by: mikeburgesss5355 | last post by:
i wish to use a "button" on a in access switchboard to edit numerous notepad txt files..these are hql files(health query language files used in healthcare gp systems). (normally about 20 notepad...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.