echo.>filename
(echo ""
would actually put "" in the file! And echo
without the '.' would put "Command ECHO activated
" in the file...)
Note: the resulting file is not empty but includes a return line sequence: 2 bytes.
This discussion points to a true batch solution for a real empty file:
<nul (set/p z=) >filename
dir filename
11/09/2009 19:45 0 filename
1 file(s) 0 bytes
The "<nul
" pipes a nul
response to the set/p
command, which will cause the
variable used to remain unchanged. As usual with set/p
, the string to the
right of the equal sign is displayed as a prompt with no CRLF.
Since here the "string to the right of the equal sign" is empty... the result is an empty file.
The difference with cd. > filename
(which is mentioned in Patrick Cuff's answer and does also produce a 0-byte-length file) is that this "bit of redirection" (the <nul...
trick) can be used to echo lines without any CR:
<nul (set/p z=hello) >out.txt
<nul (set/p z= world!) >>out.txt
dir out.txt
The dir command should indicate the file size as 12 bytes: "hello world!
".