1

I have a for loop in my batch file that loops through folders. I want to skip particular folders. I can do this with an IF statement, but would prefer a GOTO like I'm showing below.

for /d %%F in (*) do (
 if /i "%%F"=="Archive" goto nextFolder
 REM do stuff here
:nextFolder
)

But the above is giving me errors:

) was unexpected at this time
buttonsrtoys
  • 2,359
  • 3
  • 32
  • 52

2 Answers2

2

This won't work - you can't jump into a control-flow construct and expect everything to be fine.

Please take a look at (Windows batch) Goto within if block behaves very strangely for a good discussion of why this is a terrible idea.

Community
  • 1
  • 1
RB.
  • 36,301
  • 12
  • 91
  • 131
1

Rather than using GOTO, you could use NOT to exclude a folder or folders.

for /d %%F in (*) do (
   if /i NOT "%%F"=="ARCHIVE"
       REM do stuff here
)
Superbob
  • 712
  • 3
  • 5