3

bash error: ) was unexpected at this time. I need do something on all users, exept Administrator and Public

Batch file

@echo off
C:
CD \Users
for /D %%d in ("*") do (
 IF "%%d" == "Administrator" GOTO NEXT
 IF "%%d" == "Public" GOTO NEXT
 REM do something
 echo "%%d"
:NEXT
)

Output:

C:\Users\Public>batch.bat
) was unexpected at this time.

Thanks to "It Wasn't Me". The workable batch file in my case:

@echo off
CD \Users
for /D %%d in ("*") do (call :LOOP %%d)
exit /b

:LOOP

REM skip users IF "%1" == "Administrator" GOTO NEXT IF "%1" == "Public" GOTO NEXT

REM old users IF EXIST "%1"\Desktop\Unif GOTO NEXT

REM GROUP 1 IF "%1" == id395 GOTO NEW1 IF "%1" == id483 GOTO NEW1

REM GROUP 2 IF "%1" == id488 GOTO NEW2

REM others echo "do something" GOTO NEXT

:GROUP1 echo "do something" GOTO NEXT

:GROUP2 echo "do something"

:NEXT exit /b

CD \Users\Administrator

1 Answers1

2

Use the label outside the loop.

@echo off

CD /D C:\Users for /D %%d in (*)do IF "%%~d"=="Administrator" ( GOTO=:NEXT) else (echo "%%d")

:NEXT rem :: do more command here...

  • Obs.: Since you're using starting with an if, you don't need to use the do (if() else()), you can directly use the do if() else()

One alternative code to exclude user Administrator/Public:

@echo off

CD /D C:\Users

for /D %%d in (* )do echo=%%~nxd|findstr /vi "Administrator Public" >nul && ( rem :: do your command's here echo\ Current loop folder: %%~nxd )

  • One option using if() else if() else() condition:
@echo off

CD /D C:\Users

for /D %%d in (*)do if /i "%%~nxd" == "Administrator" ( rem./ Some likes do nothing/skipping... ) else if /i "%%~nxd" == "Public" ( rem./ Some likes do nothing/skipping... ) else ( rem :: do your command's here echo\ Current loop folder: %%~nxd )


Io-oI
  • 8,193