Copy security permissions of one file to another

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:

file1.bin
D:AI(A;;0x1301bf;;;BU)(A;ID;FA;;;BA)(A;ID;FA;;;SY)(A;ID;0x1200a9;;;BU)(A;ID;0x1301bf;;;AU)

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

The easiest way, by far, is to use PowerShell and run:

Get-Acl .\file1 | Set-Acl .\file2

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.