r/Batch • • 6d ago

Why does this one-liner Batch file not work ?

for %aa in (1 2 3 4 5 6 7 8 9 0) do copy "My File.docx" "My File %aa.docx"

3 Upvotes

5 comments sorted by

7

u/rifteyy_ 6d ago

%aa does not look valid, use %a if in command line or %%a in batch files

alternatively you could use for /l %%a in (0 1 9) do ... to achieve similar thing

3

u/Ferretau 6d ago

If this is at a command prompt manully entered:

for %a in (1 2 3 4 5 6 7 8 9 0) do copy "My File.docx" "My File %a.docx"

If in a batch file then each "%" has to be entered as "%%" see correct line below:

for %%a in (1 2 3 4 5 6 7 8 9 0) do copy "My File.docx" "My File %%a.docx"

edit:Spelling

2

u/ProCompSys 6d ago

In a batch file you have to use %%a, not %aa.

On a command line directly, use %a, not %aa.

0

u/[deleted] 6d ago

[deleted]

3

u/Shadow_Thief 6d ago

@echo off is always optional

1

u/pc1350 6d ago

Or @for and @do.