P
P
podde2020-09-17 18:38:27
cmd/bat
podde, 2020-09-17 18:38:27

Creating a simple .bat to create .txt files?

Hello,
please help with the syntax:
you need the batch file to create a simple empty txt file (example.txt), and the next time, if such a file already exists, it would create the file example1.txt, example2.txt, etc. .

That is, here it is:
echo Hello World1 > A:\example.txt
and what should I add so that example1 appears on the next pass of the script?
Something like IF EXIST...

Thanks in advance, I always choose Solution-Answer.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
wisgest, 2020-09-17
@podde

if exist example.txt (
  set /a counter = 1
  goto LOOP
)
copy nul example.txt
goto END

:LOOP
if exist example%counter%.txt (
  set /a counter += 1
  goto LOOP
)
copy nul example%counter%.txt

:END

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question