Making a file using Batch Files

  • Thread starter Thread starter Algren
  • Start date Start date
  • Tags Tags
    Batch File files
Click For Summary
SUMMARY

This discussion focuses on creating a .txt file using Batch Files in a Microsoft operating system environment. Users encountered issues with special characters, particularly '>' and multiple lines, when using the echo command. The recommended solution involves enclosing the text within %%"%% blocks or using single percents to bypass these issues. This method effectively allows for the writing of complex strings to a new file without syntax errors.

PREREQUISITES
  • Basic understanding of Batch File scripting
  • Familiarity with the echo command in Windows
  • Knowledge of special character handling in command line interfaces
  • Experience with Microsoft operating systems
NEXT STEPS
  • Research advanced Batch File scripting techniques
  • Learn about handling special characters in command line environments
  • Explore the use of redirection operators in Windows Batch Files
  • Investigate alternative scripting languages for file manipulation, such as PowerShell
USEFUL FOR

This discussion is beneficial for system administrators, developers working with Batch Files, and anyone looking to automate file creation and manipulation in a Windows environment.

Algren
Messages
74
Reaction score
1
How do i create a .txt file using a batch file with something written on it.

For example, i want to write this:-

i>>n;
i<<n;
a
b
c...

It has multiple lines and '>', so echo (text) >> test.txt doesn't work.

Is there a better way?
 
Technology news on Phys.org
Depending on the complexity of your task, it may be sufficient to use this technique:

Code:
It's usually enough to enclose it between two %%"%% blocks, like this:

echo %%"%% something ii >>newfile %%"%% >reg.bat

It may not look pretty but it usually works just fine.

If %%"%% doesn't seem to do what you want, try single percents like this:

Code:
echo %"% something ii >>newfile %"% >reg.bat

I no longer have a MSDOS system to try stuff out. You are likely to discover there are other characters that cause you problems when you try to echo them to a second file, too.
 

Similar threads

  • · Replies 20 ·
Replies
20
Views
5K
Replies
10
Views
5K
  • · Replies 3 ·
Replies
3
Views
3K
Replies
35
Views
7K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 57 ·
2
Replies
57
Views
6K
  • · Replies 33 ·
2
Replies
33
Views
3K
Replies
81
Views
8K
  • · Replies 29 ·
Replies
29
Views
4K