0

I am new to batch files and so far, I have figured out how to make a txt file with multiple lines

(
echo one
echo two
echo three

)>hello.txt

I found a way to do this, but it pastes the file in the same location and simply copies the txt file into another folder, but I want to put this txt file directly into that folder. Could you show me how to modify this code so that I can put this in a specific folder. Or give me an example of how you would do it this way, or another way? Thank You!

1 Answer 1

4
@Echo Off
Set "out=C:\users\YourUserName\Desktop"
(
  Echo;Line 1
  Echo;Line 2
  Echo;Line 3
) > "%out%\YourFileName.txt"

or:

@Echo Off
Set "out=C:\users\YourUserName\Desktop"
 >  "%out%\YourFileName.txt" Echo;Line 1
 >> "%out%\YourFileName.txt" Echo;Line 2
 >> "%out%\YourFileName.txt" Echo;Line 3

Where:

  • Set out : sets path to write file.
  • %Out%: specify the path with a variable.
  • \YourFileName.txt: self-explanatory.
  • > : Redirects stdout (standar output) to file. (>> indicates write, but not erase old data from file -concatenates it-).
Sign up to request clarification or add additional context in comments.

3 Comments

Hi, thanks for helping me out again! But here's the issue. One of the folders in the path has a space, and won't work with that.
@JohnSmith Did you test it. As the quotes around the filename should ensure that it works, even with spaces
Hi, I just wanted to thank you again @Honguito98 for helping me out. And yes jeb, spaces don't matter, I'm still a newbie so minor errors such as syntax were in the way, and after a little tweaking finally fixed. Thanks guys!

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.