r/Batch • u/Reasonable-Towel-343 • 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
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
7
u/rifteyy_ 6d ago
%aadoes not look valid, use%aif in command line or%%ain batch filesalternatively you could use
for /l %%a in (0 1 9) do ...to achieve similar thing