that's a big question - I'd suggest you start looking at this
A Portable and Efficient Generic Parser for Flat Files[
^] (and similar articles) if you really want to write one from scratch - its not difficult
Conceptually you need to
a) recognise each type of file
b) implement an Interface for a parser that can read the file type into an internal format
c) optionally map the input fields to the required output csv - not all fields in the input may be used for example, or re-ordered (I'd possibly use xml to describe the input file, mappings, and output file)
d) implement a csv output stage using (c)
there are 'EDI' translate engines for example that do all/some of what your asking - but many of these cost $$
btw - have you thought about a tool like Crystal reports or looked around and found something that you can drive/automate ?