I would like to replicate the permissions of a file to another. I do not want to copy the data, only the permissions.
For example, I created a new file and want it to have the same permissions as another file that already existed.
Super User is a question and answer site for computer enthusiasts and power users. It only takes a minute to sign up.Sign up to join this community
You can do it in a few steps with icacls and a text editor.
First you must save the permissions of the original file
icacls C:\test\file1.bin /save perms.txt
you will need to edit the
perms.txt file you just created in whatever folder you ran
icacls in. The file should look something like this:
You can ignore all the stuff on the 2nd row, all we care about is the first row. Change the
file1.bin to your new filename
file2.bin and save the file.
Now you just need to restore the file permissions on the 2nd file, note that we did not include the filename this time. (If you get an error that says "Not all privileges or groups referenced are assigned to the caller." run the program again in an elevated command prompt.)
icacls C:\test\ /restore perms.txt
To make it in a batch (copy security pemissions from a subfolder or all folders of one drive to the same folder/file stricture on another drive), create a, say,
cpdacls.bat file with this content:
@echo off for /r %1 %%f in (.) do call :icacls_one %%f %2 goto :eof :icacls_one icacls %1\*.* /save %TEMP%\perms.txt icacls %2.%~pnx1 /restore %TEMP%\perms.txt del /q %TEMP%\perms.txt
And then run it like
cpdacls.bat e:\ f:\.
Note that the folder structure in the destination folder must be the same as folder structure in the source folder, taken from its root, not depending on what subfolder you have specified as a source folder.
The easiest way, by far, is to use PowerShell and run:
Get-Acl .\file1 | Set-Acl .\file2