JSI Tip 5605. How can I copy a folder's contents to another folder and preserve ownership and permissions?

When you use Explorer to copy files from a source to a destination folder, the files receive the permissions of the destination folder, and you become the CREATOR OWNER.

You can use Xcopy to retain directly assigned permission:

xcopy source destination /O /X /E /H /K

where:

/E - Copies folders and subfolders, including empty ones.
/H - Copies hidden and system files also.
/K - Copies attributes. Normally, Xcopy resets the read-only attribute.
/O - Copies file ownership and ACL information.
/X - Copies file audit settings (implies /O).

Using these switches:

The security settings that are directly assigned to the files and folders are preserved.
The security settings that are inherited from the source parent folder are dropped.
The security settings of the destination folders are also inherited.

NOTE: FAT volumes have no security settings.

NOTE: See tip 5409 » How do I use Robocopy to copy ACLs without copying data?



Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish