1.

Solve : Inserting EOF in a batch file?

Answer»

I want to make a batch file that erases all the contents in a .txt file.

I was thinking about making a new file with the same name, but can't get it to insert the EOF character in the file, so the user doesn't have to.

Is there a way of doing this?...or maybe an easier way to erase the contents.

Thanks beforehand

Two-eyes

just TYPE 00>C:\folder\Yourfile.txtWindows txt files do not have an eof character, if by that you mean ctrl-z ASCII 26.

On modern OSes, the EOF character doesn't actually end a file - the size of the file is EXPLICITLY stored in the filesystem, and the contents can be anything.

On older systems the file size was only stored with a certain level of PRECISION, and the EOF character was used on text files to determine where in the last block of data the file ended.

In certain cases when dealing with text files or reading data from a "character device", the Microsoft MS-DOS shell (COMMAND.COM) or operating-system utility programs would historically append an ASCII control-Z character to the end of a disk file (though the basic kernel MSDOS.SYS file write CALLS never appended a control-Z). This was done for backward compatibility with some of the peculiarities of CP/M, since the CP/M file system only recorded the lengths of files in terms of how many 128-byte "RECORDS" were allocated. The MS-DOS filesystem has always recorded the exact byte-length of files from its very first version.

In Windows and DOS you can blitz a text file by just echoing a cr + lf to overwrite it thus:

Code: [Select]echo.>Yourfile.txt

Quote

I want to make a batch file that erases all the contents in a .txt file.

Could you explain why you can't just delete the text file?
the "00>c:\folder\myfile.txt didn't work" ... "00 is not an internal or external command"
The "echo. > myfile.txt" worked like a charm (although I can't say i perfectly understood what you said Dias  )
Thanks very much.

Y'all a great community: 1hour from post I get an answer.
ThanksAbout the Quote
Quote
I want to make a batch file that erases all the contents in a .txt file.

Could you explain why you can't just delete the text file?

I only want to remove the contents not the file. I will be writing new information on the file.  I tried to save the name and create a new file (temp), delete the older one, then change the name of temp.txt.  But i needed to show that i wanted and empty temp.txt, i wanted to insert ^Z and couldn't find a way to do that.
Hope you understood my long sentence. umm- just use > instead of >> when you want to delete it. > will overwrite the entire contents of the file, after which you can use >> to append more.


Discussion

No Comment Found