0

Let's say my destination directory already contains some files. My source directory contains identical files PLUS some extra files that are not in the destination and I want to copy these extra files. I know I can:

robocopy c:\source_path c:\destination_path /e /xc /xn /xo

However, I want to copy the these files into a different directory from the destination. In other word, I want to keep these files that are not in the destination separate from the files already in the destination.

How do I do that? I am using Windows 10 if that matters.

EDIT 2020/4/2:

harrymc's answer didn't quite work.

powershell "Get-ChildItem -Path 'c:\source_path` -exclude (Get-ChildItem -Path `c:\exclusion_path`) | Copy-Item -Destination 'c:\destination_path'"

This only copies files directly under the \source_path and ignore all subdirectories (My bad - I didn't mention anything about subdirectory).

When I include option -Recurse as in:

powershell "Get-ChildItem -Path 'c:\source_path` -exclude (Get-ChildItem -Path `c:\exclusion_path`) -Recurse | Copy-Item -Destination 'c:\destination_path'"

it places all subdirectories (in all levels) under \destination_path as EMPTY folders, and place all files (in all subdirectories) directly under \destination_path, overwriting any files if there are multiple files with the same name in separate directories in \source_path. PLUS, no files or directories in \exclusion_path were excluded (\source_path and \exclusion_path have the same directory structure). I don't understand how this is supposed to work.

1 Answer 1

0

Robocopy is not the right tool for this job. PowerShell is much better, where this can be done with a one-liner.

Assuming copying from c:\source_path to c:\destination_path but excluding all in c:\exclusion_path:

Get-ChildItem -Path 'c:\source_path` -exclude (Get-ChildItem -Path `c:\exclusion_path`) | Copy-Item -Destination 'c:\destination_path'

To make it work from CMD, write it like this:

powershell "Get-ChildItem -Path 'c:\source_path` -exclude (Get-ChildItem -Path `c:\exclusion_path`) | Copy-Item -Destination 'c:\destination_path'"
2
  • Thank you for your answer. Unfortunately it didn't really work. See my edit in the original question.
    – SE145TH
    Commented Apr 2, 2020 at 20:49
  • Better define very clearly with examples what you are trying to achieve, including sub-folders.
    – harrymc
    Commented Apr 3, 2020 at 6:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .