0

I'm trying to execute a command for every folder with the name "day*".

The following is my code:

FOR /D [/r] %%G IN (\tool\%server%\%day*) DO (
    ***code to copy and paste from one folder to another***
)

My computer gives me the following errors:

[/r] was unexpected at this time

when I tried removing [/r]

%%G was unexpected at this time
phuclv
  • 37,963
  • 15
  • 156
  • 475
mylkcha
  • 89
  • 9
  • 2
    remove the rectangular brackets. – npocmaka Feb 27 '18 at 09:33
  • 3
    Rectangular brackets in syntax means something optional. – ACatInLove Feb 27 '18 at 09:37
  • 2
    I assume you are testing this not with a batch file but within the CMD itself. If so, you need to use `%G` instead of `%%G`. Also, your wildcard doesn't need a `%` in the front as well. – FatalBulletHit Feb 27 '18 at 10:04
  • Possible duplicate of [How to read API documentation for newbs?](https://stackoverflow.com/questions/10925478/how-to-read-api-documentation-for-newbs) – phuclv Feb 27 '18 at 10:51
  • [What do the brackets around the arguments mean](https://stackoverflow.com/q/21654192/995714), [What do square brackets mean in function/class documentation?](https://stackoverflow.com/q/1718903/995714) – phuclv Feb 27 '18 at 10:52
  • DOS doesn't have `for /r`. It's a feature of cmd.exe [which is a different environment](https://superuser.com/q/451432/241386) – phuclv Feb 27 '18 at 15:14
  • Here is the [Microsoft Article](https://learn.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2012-R2-and-2012/cc771080(v=ws.11)) that explains the documentation syntax. – Squashman Feb 27 '18 at 16:02

0 Answers0