Search code examples
loopsbatch-filecacls

looping the CACLS function in batch


I would like to lock a series of file from my staff so they can not delete them i have thus compiled a script wich puts the CACLS function into a loop. however this is not taking effect.

could somebody please explain why?

FOR /F %%i IN (c:\file.txt) DO CACLS %%i /p :n /y

I have been able to narrow it down to the /y at the end how can i continue to Automate the yes?


Solution

  • There are a couple of things wrong.

    Firstly you haven't specified a user/group that you want to apply the permissions to

    Example

    CACLS %%i /p Everyone:n /y
    

    Secondly, there is no /y switch for cacls. If you want to automatically say y to the confirmation you can use this

    echo y| CACLS %%i /p Everyone:n /y
    

    So your full batch file would look similar to this

    FOR /F %%i IN (c:\file.txt) DO echo y| CACLS %%i /p Everyone:n
    

    Hope this helps