WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Functions

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

FileWrite Adds CRLF

Keywords: 	  FileWrite Adds CRLF

Question:

I have found that when I use FileWrite to create a file, it seems to add an extra, blank line at the end of the file

For instance this code:

hh = FileOpen("C:\temp\test.txt","Write")
For x = 1 to 5
FileWrite(hh,"ABC")
FileWrite(hh,"123")
FileWrite(hh,"XYZ")
FileWrite(hh,"789")
next
FileClose(hh)
should create a file with 20 lines. In reality, it adds an additional blank line at the end of the file. How can I keep that line from being added to the output file?

Answer:

Hmmm. This is all going to hinge on the rather ambigious definition of line.

FileWrite, by default, adds a CRLF to the end of every string you write.

In this case a line is defined as 0 or more normal characters followed by a CRLF character pair.

When I tested the script, that is exactly what I got.

However I surmise that you wish to perhaps not add the final CRLF on the end?

Or perhaps you are looking at it in WinBatch Studio that seems like to make sure the end of the file has a CRLFRLF on the end and thus confuses the issue?

In any case you can use IntControl 53 to take control of the kind of endings yourself and write out exactly what text you want.


Article ID:   W15501
File Created: 2003:05:13:11:28:22
Last Updated: 2003:05:13:11:28:22