2

I want to create new file and to add info in it. But at the beginning I want to clear all its information. So I wrote:

@if "%DEBUG%" == "" @echo off
@rem ############################################
@rem # Create new empty file                    #
@rem ############################################

:setup
if "%OS%"=="Windows_NT" setlocal
SetLocal EnableDelayedExpansion
goto create

:create    
@cmd /c echo( >%temp%\hosts
goto end

:end
if "%OS%"=="Windows_NT" endlocal
PAUSE

But when I open the file there is leading empty line

<empty line>
SomeInfo

Where is just empty line. How to create new file with no leading empty line?

1

3 Answers 3

4
break>empty.file

My favorite way..

Break is an internal command so it is fast.And almost allays produces empty output (he only exception is /?) no matter of the arguments , which reduces the chance of errors. And never does changes to the environment.

Sign up to request clarification or add additional context in comments.

Comments

3
>empty.file @echo off

Just wanted to throw this out there, but I would recommend the break or set /p methods first. This method along with creating a blank file will also turn command-echoing off

Also, here is an alternate method of the set /p method using nul input.

>empty.file set /p "=" <nul

Comments

1
ECHO.|SET /P A="">empty.file

SET /P doesn't emit newlines.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.