How to create empty text file from a batch file?
echo. 2>EmptyFile.txt
type NUL > EmptyFile.txt
After reading the previous two posts, this blend of the two is what I came up with. It seems a little cleaner. There is no need to worry about redirecting the "1 file(s) copied." message to NUL
, like the previous post does, and it looks nice next to the ECHO OutputLineFromLoop >> Emptyfile.txt
that will usually follow in a batch file.
copy NUL EmptyFile.txt
DOS has a few special files (devices, actually) that exist in every directory, NUL
being the equivalent of UNIX's /dev/null
: it's a magic file that's always empty and throws away anything you write to it. Here's a list of some others; CON
is occasionally useful as well.
To avoid having any output at all, you can use
copy /y NUL EmptyFile.txt >NUL
/y
prevents copy
from asking a question you can't see when output goes to NUL
.