Thursday, May 26, 2011

Merging files

Some time back we faced a simple situation. Its nothing but we need to merge a good number of files into one file. It was not a one time process. We may need to do it when ever any of the files change because those files are residing in the TFS source control.

We wanted to do it simply .ie without writing a .Net program.Normally developers have a tendency to write program even for small things .The first method was to use the copy command.Yes the same DOS command copy. We were able to do that as follows till the files grew beyond MBs.

Copy *.* c:\combined.sql

When the individual files grew bigger ie to MBs this command started appending some unwanted characters into the out put file. This prevent us from executing the sql files using SQL Server Management Studio.

Obviously the next solution was powershell.We got a script to combine files with in no time.Its simple,open source to modify,no need to compile but when we look at that it’s almost the same .net classes and code except some syntax changes Smile.

Uploaded the script here.I am not sure from which site I got this..

No comments: