Home > Microsoft > How to copy folders and keep NTFS and Share Permissions

How to copy folders and keep NTFS and Share Permissions

I have a client that has created a template folder structure for their client files that has the required permissions set up on them.

What the client wants to do is copy this template structure to a new folder whenever they get another client and keep the folder security that they have applied to their template folder structure.

And here is how it can be done.

This is an easy enough task to accomplish, but cannot be done through the Explorer interface as Microsoft’s explorer adheres to the following rules:

  1. When you copy a folder to the same drive it will inherit the permissions from the new location.
  2. When you moving a folder on the same drive, it will keep its own permissions
  3. when you copy the folder to another drive, it will inherit the permissions from the new location.
  4. When you move a folder to another drive, it will inherit the permissions from the new location.

So given this dilemma, how do you copy the folder and keep the NTFS and Share Permissions?

Well you use Xcopy.

On windows XP and windows Server 2000/3, you can Click “Start” then “Run” and type “cmd”, then press “Enter”

On windows Vista, Windows 7 and Windows Server 2008 you can click the start button then type “cmd” in the search box and you should get cmd listed. Right click the cmd in the list and chose “Run as administrator”.

CMD Run as for windows 7 and vista

If UAC is enabled click yes when prompted

CMD UAC Prompt

Once the command Prompt is open, you can then type the following command to copy the folder template.

Xcopy source Destination /O /X /E /H /K

Xcopy command with permissions

Remember that for folders with spaces in the name or folders larger than 8 characters in length, it is a good idea to put quotation marks around the path as in the figure above or you may get an error.

You could take this a step further and write a script that prompts for the source and destination, and it then can automate the copy process for the end user, but this is beyond the scope of this article.

Let me know by way of comments to this article, if you are interested in having another article for how to create the script.

  1. Amar Honnungar
    September 3rd, 2013 at 12:19 | #1

    All the security permission can be copied to remote destination folder using RoboCopy. I have used RoboCopy as this is abetter solution than using FileServer transfer/migration wizard

  2. Daniel_Laixer
    February 19th, 2015 at 12:13 | #2

    Thanks for the command

    BTW, /O is not necessary in this case because /X implies /O

  1. No trackbacks yet.