Robocopy command to copy updated files and long path names
I'm trying to write a robocopy
command to copy from folders SR
to DS
.
Folder DS
might have files that already exist in Folder SR
, but if Folder DS
is updated, don't overwrite it. If folder/files don't exist in folder DS
, copy them, keep the same security permissions (shared and NTFS) and timestamp on the files/folders.
I've tried:
Robocopy Source Des /XN /E
The problem is it keeps overwriting the data and another problem is that I have a long pathname over 320 characters which robocopy
won't copy.
I think the /XN is the problem , please check this link: https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/robocopy#remarks as we know that : /xn = Excludes newer files.
/E = Copies subdirectories. this option includes empty directories.
- I think you need to use a different switch check :
/maxlad:Specifies the maximum last access date (excludes files unused since N).
/minlad:Specifies the minimum last access date (excludes files used since N) If N is less than 1900, N specifies the number of days. Otherwise, N specifies a date in the format YYYYMMDD.
-- for the issue of long path name , I have a solution but it will take much time , so to not consume more time any of GUI tools that solve this problem easily , try to google rsync , gsrichcopy 360 or teracopy , the good news that also these can solve the issue of the recent files or updated one , but first check my solution that I mentioned above
You can try to copy from Folder DS to Folder SR -- with the option to copy only newer files. Then copy Folder SR to Folder DS. It sounds as if there might not be too many files in Folder DS which are newer, and so this won't add much time.
And in the end, both folders would be completely up to date.
This really depends on the details of your need, but might be what you want to do.
This is a solution which you can try to apply or you can switch to robocopy alternatives which are mentioned by other users.