Making a file using Batch Files

In summary, the conversation discusses techniques for creating a .txt file with specific content using a batch file. The suggested method involves using %%"%% blocks or single percents to enclose the desired text. However, it is mentioned that other characters may cause problems when trying to echo them to a second file. The conversation also provides a resource for more ideas on this topic.
  • #1
Algren
74
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
  • #3
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.
 

1. How do I create a batch file?

To create a batch file, open Notepad and type in your desired commands. Save the file with a .bat extension and it will automatically become a batch file.

2. How do I run a batch file?

To run a batch file, simply double-click on the file and it will execute the commands within it.

3. How do I add comments to a batch file?

To add comments to a batch file, use the REM command before your comment. This will ensure that the comment is not executed as a command.

4. How do I add variables to a batch file?

To add variables to a batch file, use the SET command followed by the variable name and its value. You can then use the variable throughout the batch file.

5. How do I create a loop in a batch file?

To create a loop in a batch file, use the FOR or the WHILE command. These commands allow you to repeat a set of commands until a certain condition is met.

Similar threads

  • Programming and Computer Science
Replies
20
Views
529
  • Programming and Computer Science
Replies
2
Views
381
  • Programming and Computer Science
Replies
10
Views
4K
  • Programming and Computer Science
Replies
3
Views
2K
  • Programming and Computer Science
Replies
33
Views
2K
  • Programming and Computer Science
2
Replies
57
Views
3K
  • Programming and Computer Science
Replies
2
Views
1K
  • Programming and Computer Science
3
Replies
81
Views
5K
  • Programming and Computer Science
Replies
29
Views
2K
  • Programming and Computer Science
Replies
5
Views
384
Back
Top