-5

I wanna create a txt file only using a batch file that has multiple lines in it For example :

In the txt file it will have:

  • I like to program
  • But I also like my name

But I cannot do that with :

echo I Like to program, But I also like my name > Test.txt

Any help with this?

2 Answers2

1

Approach 1: FINDSTR

;@echo off
;findstr /V /R "^;" "%~f0" >text.txt
;exit /b
I like to program
But I also like my name

Approach 2: Multiline strings

Unix (LF) endings:

@echo off
====SETLOCAL DisableDelayedExpansion EnableExtensions

set ^"LF=^
%====DO NOT REMOVE ME====%
"
set ^"NL=^^^%LF%%LF%^%LF%%LF%^^"

<nul >text.txt set/p^"=SO%NL%
MANY%NL%
LINES^!"

If you want Windows (CRLF) endings:

FOR /F "skip=3" %%C in (
'%__APPDIR__%wbem\wmic.exe os get Name'
) do set ^"NL=%%C^^^%LF%%LF%^%LF%%LF%^^"
ScriptKidd
  • 803
  • 1
  • 5
  • 19
0

Is this what you're trying to do?

@(  Echo I Like to program
    Echo But I also like my name
    Echo This is my next line
    Echo This is my etc. …
) 1> "Test.txt"
Compo
  • 36,585
  • 5
  • 27
  • 39
  • Kind of, but it still doesnțt work. – burnyourfellings May 30 '20 at 15:17
  • 3
    One thing I can guarantee @burnyourfellings, is that the code above works flawlessly. If there is anything else in your batch file at all remove it, my code is a complete batch file and should only be tested as is, and with absolutely no modifications. Any other issue is outside of the scope of your question and my answer, unless you fully explain it. – Compo May 30 '20 at 17:20