Chage Permissions on Series of Folders

We recently ran into an issue where we needed to attach a larger drive to one of our servers to increase the available disk space. Unfortunately when the files and folders were copied to the new drive, existing permissions were lost.  Since the drive contained multiple instances of the same application we knew there were a large number of folders and files that ultimately would need the same permissions applied to them.

Initially the answer seemed to be icacls which is a windows program that allows you to set permissions from the command line. Unfortunately icacls supports wildcards for file names but doesn't support wildcards for folder names. That means there was no easy way to use icacls to apply the same permissions to all the matching subfolders in our web directory.

Ultimately we came up with this handy batch file that loops through all the folders in a directoy and then uses icacls to apply the appropriate permissions.

Just copy and paste this into a .bat file, update the variables to match your environment and you should be all set. Hope this helps somebody else out there.

@echo off
for /D %%f in ("D:\Websites*") do for /D %%d in ("%%f\*") do icacls "%%d\Uploads/" /inheritance:e /grant "Everyone":(OI)(CI)F

Tags: Development , Web Development , Windows , IIS ,

Just Some of our Happy Clients...