how to empty txt-files without deleting them

  • Thread starter Thread starter Rocky
  • Start date Start date
R

Rocky

Hi,
I have a series of .txt-files (sort of logfiles) in one directory which
should be emptied from time to time, without deleting the files themselves.
Is there a way to automise this?
Thanks!
 
You can
echo .>filename.txt
to overwrite an existing file to get a file containing a CRLF. Note that you
will get one blank line at the top of the file, and the file size will be
two bytes. If this is a problem, you could create a zero length file, and
copy that over the file you want to truncate. Or, you can look at any number
of scripting options, simple programs, or shareware tools.
 
-----Original Message-----
Hi,
I have a series of .txt-files (sort of logfiles) in one directory which
should be emptied from time to time, without deleting the files themselves.
Is there a way to automise this?
Thanks!


.

Most programs that create .txt files will re-create them
if they aren't present.

If this isn't the case, then you can just copy some blank
files into that directory. Put your blank .txt files in a
new directory, and create a .bat file to copy them to the
directory you want to put them.

Example of the .bat file:

Attrib /s -r c:\ops\*.txt
copy c:\blankfiles\*.txt c:\ops\*.txt
pause


Run this file from a cmd prompt to see what the outcome is.

HTH
 
Greg Stigers said:
You can
echo .>filename.txt
to overwrite an existing file to get a file containing a CRLF. Note that you
will get one blank line at the top of the file, and the file size will be
two bytes. If this is a problem, you could create a zero length file, and
copy that over the file you want to truncate. Or, you can look at any number
of scripting options, simple programs, or shareware tools.

type nul>filename.txt will create a zero-byte file.
 

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

Back
Top