I want to create a file named “new text document.txt” in the folder %tv% using a batch file ( *.bat). This is my batch file:
set tv=D:\prog\arpack96\ARPACK\SRC
cd "%tv%"
@CON >> "new text document.txt"
set tv=
Although I can really create the file in %tv%, but when I run the above batch file, I will get an error message saying
‘ ‘ is not recognized as an internal
or external command, operable program
or batch file.
Is there anyway to get rid of this error message? Or I am creating the file using the wrong command?
In order to get a truly empty file without having to provide user interaction, you can use the
set /pcommand with a little trickery:The
set /pasks the user for input into thetvvariable after outputting the prompt after the=character.Since the prompt is empty, no prompt is shown. Since you’re reading from nul, it doesn’t wait for user interaction. And you can store the empty string straight into
tvthus removing the need to unset it.Actually, after some more thought, there’s an easier way. I’ve used that
set /ptrick in the past since it’s the only way I know of echoing text without a newline being added (great for progress bars in the console). But if all you want is an empty file, you can probably get away with:The
copysimply copies the contents of thenuldevice (effectively an empty file) to your new file name. The/yis to ensure it’s overwritten without bothering the user.