您需要生成要處理的文件列表,並排除不想要的文件列表,因爲CACLS不允許過濾。
在這裏,我使用「dir」來生成要處理的文件列表。 你也可以使用「forfiles」。
(您可以使用管道使腳本更緊湊,但我使用的是臨時文件,而不是爲了使其更清晰)。
@echo off
setlocal
set TMPFILE=%TEMP%\dirs.txt
set TMPFILE2=%TEMP%\dirs2.txt
@rem Generate the list of dir names to be processed
dir "%~1" /ad /s /b /p > %TMPFILE%
@rem Filter out the unwanted ones
findstr /i /v /C:"myDir\A\B\C" < %TMPFILE% > %TMPFILE2%
@rem And execute a command on each
for /F "delims=;" %%x in (%TMPFILE2%) do call :dostuff "%%x"
goto :EOF
:dostuff
@rem do the directory itself
cacls "%~1\ /E /G myUser:F
@rem do the files
cacls "%~1\*" /E /G myUser:F
goto :EOF
你有沒有嘗試過呢? – captcha
另一種解決方案是添加第二個命令,從文件夾中刪除「myuser」訪問權限。 – foxidrive