Wednesday, January 28, 2015

Exact Copy of a File or Folder using XCOPY

If we copied a file or folder and paste in another or same folder, the permissions set on the folder will reset to the default inherited permission from its parent.
In some cases we will need to set same permissions to a set of subfolders. It will be easy if we can copy the permissions to each one of the sub folders. There is an easy way to do this.
Create one subfolder and set all necessary permissions on that folder. then copy that subfolder with xcopy command and it will restore all the file structure and file permissions.

Syntax:
XCOPY [Source] [Destination]  [/O] [/X] [/E] [/H] [/K]

These switches have the following effects:
/E - Copies folders and subfolders, including empty ones. 
/H - Copies hidden and system files also. 
/K - Copies attributes. Typically, Xcopy resets read-only attributes.
/O - Copies file ownership and ACL information.
/X - Copies file audit settings (implies /O). 

NOTE: This procedure does not override inherited permissions. When you use the Xcopy command with the /O /X /E /H /K switches to copy the files, the following inherited permissions apply:
  • The security settings that are directly assigned to the files and folders are retained.
  • The security settings that are inherited from the source parent folder are lost.
  • The security settings of the destination folders are inherited.
  • When you move files or folders to FAT volumes, the folders and files lose their NTFS permissions because FAT volumes do not support NTFS permissions.
Eg:

xcopy c:\olddocs c:\newdocs /O /X /E /H /K,

xcopy Computer Electronics  /O /X /E /H /K

No comments:

Post a Comment