bash 错误:)此时是意外的。我需要对所有用户执行某些操作,管理员和公共用户除外
批处理文件
@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
)
输出:
C:\Users\Public>batch.bat
) was unexpected at this time.
感谢“这不是我”。对我来说,可用的批处理文件是:
@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
在循环外使用标签。
@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...
- 观察:由于您使用的是以 开头的
if
,因此无需使用do (if() else())
,您可以直接使用do if() else()
排除用户管理员/公共的一个替代代码:
@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
)
- 使用条件的一个选项
if() else if() else()
:
@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
)