2

I am fairly new to any programming.
I have a task to perform in which the requirement is detailed below:

  1. There should be created 65536 text files.
  2. Each file must have a name starting from 1.txt to 65536.txt.
  3. Each file will have a certain text in it, in which at a particular place the file name must appear. For example, the existing text looks like DIAGRAM VARIABLE 0 0 1098 5 6. The number 1098 in this text must be the number in file name.
2
  • Sounds like you're looking for a for /L loop. Commented Sep 1, 2015 at 6:43
  • 1
    Welcome at SO. Unfortunately, we are not a code-writing service. However, combination of next sources should lead to solution: FOR /L loop command, ECHO command and > Redirection Commented Sep 1, 2015 at 6:47

1 Answer 1

1

You can try this (havent tested) for /l iterates %%x from 1 to 65536 and then echo writes whats left of the > to the filename specified to the right.

for /l %%x in (1, 1, 6 ) do (
 echo STRING TO BE WRITTEN NO %%x > %%x.txt
)
Sign up to request clarification or add additional context in comments.

3 Comments

You're going to want to put a 1 directly before the >, or else you're going to end up redirecting the wrong input to the files. (Alternatively, you can put the >%%x.txt at the start of the line.) Also, a for /L loop from 1 to 65536 totally works, although I admit that I'm a little surprised that it does.
if i run that echo string in a batch-file, it writes the file as expected. No need to add the 1 or swap the order
Ah, it's the space you have before the > that's keeping it from breaking. I didn't include it in my test.

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.