Read Text File and split them to individual text file

K

Krish

I have requirement, that i get one big chunk of text file. This text file
will have has information, that on finding "****End of Information****", i
have to split them individual text file with our naming standard (unique id)
and create them designated folder.

This requirement should be created as a batch job and preferrably this job
should monitor the folder where one big chunk of text file lands and process
them immediately.

\\Textfile\IN folder => one big chunk text file comes here by different
source

\\Textfile\Output\yyyyddmm folder => i need to process (split) the text file
coming "IN" folder to different text files based on "End of Information"
delimiter.

I need to achieve this using dot net preferrably using Csharp. Pl. note that
i have recently started learning cSharp but has almost 6 years experience of
using Visual Basic & COM + etc.

Pl. throw any thoughts that you may want to share.

To tell you how the text file will look
unique ID : 999
Text blah blah blah blah......
something here..
some information ...
"****End of Information****"
unique ID : 999
Text blah blah blah blah......
something here..
some information ...
"****End of Information****"
unique ID : 999
Text blah blah blah blah......
something here..
some information ...
"****End of Information****"



Thanks,
Krish
 
N

Nicholas Paldino [.NET/C# MVP]

Krish,

First, you will need to use the FileSystemWatcher class. You can
specify the directory of your input files to watch, and be notified when a
new file is created there.

Once you do this, you can use the FileStream class to open a stream for
reading, as well as for new streams to write your new files.

You can also use the StreamReader class to wrap the FileStream reader.
This will allow you to read lines (assuming that your delimiter takes a line
to itself). You can also use the StreamWriter class to make writing the
strings to the new file easy.

Then, you can use the static CreateDirectory method on the Directory
class to create your new directory to output your files.

All of these classes are in the System.IO namespace.

Hope this helps.
 
K

Krish

Excellent. The points you have mentioned will give me good start.

Krish

Nicholas Paldino said:
Krish,

First, you will need to use the FileSystemWatcher class. You can
specify the directory of your input files to watch, and be notified when a
new file is created there.

Once you do this, you can use the FileStream class to open a stream for
reading, as well as for new streams to write your new files.

You can also use the StreamReader class to wrap the FileStream reader.
This will allow you to read lines (assuming that your delimiter takes a
line to itself). You can also use the StreamWriter class to make writing
the strings to the new file easy.

Then, you can use the static CreateDirectory method on the Directory
class to create your new directory to output your files.

All of these classes are in the System.IO namespace.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Krish said:
I have requirement, that i get one big chunk of text file. This text file
will have has information, that on finding "****End of Information****", i
have to split them individual text file with our naming standard (unique
id) and create them designated folder.

This requirement should be created as a batch job and preferrably this
job should monitor the folder where one big chunk of text file lands and
process them immediately.

\\Textfile\IN folder => one big chunk text file comes here by different
source

\\Textfile\Output\yyyyddmm folder => i need to process (split) the text
file coming "IN" folder to different text files based on "End of
Information" delimiter.

I need to achieve this using dot net preferrably using Csharp. Pl. note
that i have recently started learning cSharp but has almost 6 years
experience of using Visual Basic & COM + etc.

Pl. throw any thoughts that you may want to share.

To tell you how the text file will look
unique ID : 999
Text blah blah blah blah......
something here..
some information ...
"****End of Information****"
unique ID : 999
Text blah blah blah blah......
something here..
some information ...
"****End of Information****"
unique ID : 999
Text blah blah blah blah......
something here..
some information ...
"****End of Information****"



Thanks,
Krish
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top