I have a series of folders which receive .pdf files from paper scans made by staff at a photocopier. One folder per Business Unit on a Windows 2000 server, so:
Scan$ Unit 1\ Unit 2\ Unit 3\ What I'm trying to do is write a batch file to create a folder named:
'Temp area - files will be deleted after 14 days !'
and place it into each of the Unit 1,2,3 'root' folders to remind staff not to store data there long-term. Once I have created that folder I need to set the NTFS perms, maybe with icacls, to only allow Domain Admins to access the folder I created, so staff cannot delete it.
I've written batch files before to create 'home' folders reading names from a .txt, eg for /f %%a in (users.txt) do ..icacls \\filer\Personal$\Home\%%a /grant:r "Company\Domain Admins:(OI)(CI)F"
I'm struggling with this issue, any help appreciated :-)
21 Answer
You should be able to accomplish this with this simple script:
@ECHO off
SET _Path=\\unc\scan$
SET _FolderName=Temp area - files will be deleted after 14 days!
for /f "delims=" %%a in ('dir "%_Path%" /B /R /AD') DO ( mkdir "%_Path%\%%a\%_FolderName%" icacls "%_Path%\%%a\%_FolderName%" <...>
)Breakdown
SET _Path=\\unc\scan$sets a variable holding the path to the folder containing theUnit 1,Unit 2,Unit 3folders. Setting this in only one places makes it easier to change in the futureSET _FolderName=Temp area - files will be deleted after 14 days!sets a variable holding the name of the folder you want to create and lockdir "%_Path%" /B /ADlists the subdirectories in the path you specifiedfor /f "delims=" %%a in ('dir "%_Path%" /B /R /AD') DOwill loop through the subdirectoriesmkdir "%_Path%\%%a\%_FolderName%"creates your new subdirectories using the folder name specifiedicacls "%_Path%\%%a\%_FolderName%" <...>will run youricaclsto set the permissions. You'll have to replace<...>with whatever/grantor/denypermissions you want to set.