Antonio King
asked on
if then inside for loop not working - Batch scripting
Hi
I have created a batch script that adjusts folder ownership and permissions. The script recursively cycles through all subfolders names of a folder. The names of the folders are usernames. The script assigns folder ownership and full permissions to the that user. Ie. If the folder name is "JBloggs", then Jbloggs will be made the owner and be granted full permission.
There is one folder I do not want the script to touch. This folder is called "default"
I've added an IF then NEQ statement so if it encounters a folder with the name "default" it will just skip over it, but it doesn't seem to be working.
Any advice would be greatly appreciated!
I have created a batch script that adjusts folder ownership and permissions. The script recursively cycles through all subfolders names of a folder. The names of the folders are usernames. The script assigns folder ownership and full permissions to the that user. Ie. If the folder name is "JBloggs", then Jbloggs will be made the owner and be granted full permission.
There is one folder I do not want the script to touch. This folder is called "default"
I've added an IF then NEQ statement so if it encounters a folder with the name "default" it will just skip over it, but it doesn't seem to be working.
Any advice would be greatly appreciated!
@ECHO OFF
SETLOCAL enabledelayedexpansion
CD /D "D:\Public\Users\"
FOR /D %%A IN (*) DO (
IF %%A NEQ "default" THEN (
REM TAKEOWN /F "%%A" /A /R /D Y
REM ICACLS "%%A" /RESET /T
REM ICACLS "%%A" /GRANT:R "DOMAIN\%%A:(OI)(CI)F"
REM ICACLS "%%A" /SETOWNER "DOMAIN\%%A" /T
ECHO %%A >> C:\Public\Scripts\Log.txt
)
)
ENDLOCAL
EXIT
ASKER
Hi Bp
Thanks for taking the time to look at this for me.
IO've made your recommended adjustments, however the name "default" is still appearing in the log.log file suggesting the changes have not had the desired affect.
To confirm, this is now the script I'm using...
Thanks for taking the time to look at this for me.
IO've made your recommended adjustments, however the name "default" is still appearing in the log.log file suggesting the changes have not had the desired affect.
To confirm, this is now the script I'm using...
@ECHO OFF
SETLOCAL enabledelayedexpansion
CD /D "D:\Public\Users\"
ECHO The following folders permissions have been changed: > "C:\Public\Scripts\Folder permissions\log.log"
FOR /D %%A IN (*) DO (
IF /i "%%A" NEQ "default" THEN (
REM TAKEOWN /F "%%A" /A /R /D Y
REM ICACLS "%%A" /RESET /T
REM ICACLS "%%A" /GRANT:R "DOMAIN\%%A:(OI)(CI)F"
REM ICACLS "%%A" /SETOWNER "DOMAIN\%%A" /T
ECHO %%A >> "C:\Public\Scripts\Folder permissions\log.log"
)
)
ENDLOCAL
EXIT
Can you post the log file here? If not, please post the exact line(s) that have DEFAULT in them.
~bp
~bp
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
See my last comment (before this one) about the THEN in the IF...
~bp
~bp
ASKER
Thanks! What a rookie error!
Sometimes a fresh pair of eyes is needed.
Sometimes a fresh pair of eyes is needed.
Welcome, glad that helped.
~bp
~bp
Open in new window
~bp